git 错误 - 不匹配 git 已知的任何文件?

git error- did not match any file(s) known to git?

我在 .git 目录中的 .info 内的排除文件中添加了一个递归忽略文件的模式。

patter : httpdocs/**/bak_*.*

如果我从 httpdocs 提交它正在工作,并且从更改后的目录提交错误。

git commit -m "formatting js" httpdocs/* [working]

git commit -m "formatting js" httpdocs/dir1/dir2/* [giving below error]

错误: pathspec 'httpdocs/dir1/dir2/bak_admin.abc.php' 不匹配 git.

已知的任何文件

基本上我想知道为什么会这样。

* 通配符模式由 shell 扩展( 而不是 git)。
这意味着 git commit -m "formatting js" httpdocs/*

翻译
 git commit -m "formatting js" httpdocs/fileorDir1
 git commit -m "formatting js" httpdocs/fileorDir2
 git commit -m "formatting js" httpdocs/fileorDir3

如果所有这些文件都已被跟踪,git 提交工作。如果不是,则会返回您看到的错误消息。

git commit -m "formatting js" httpdocs/dir1/dir2/*的情况下,翻译为:

git commit -m "formatting js" httpdocs/dir1/dir2/fileirDir1
git commit -m "formatting js" httpdocs/dir1/dir2/fileirDir2
git commit -m "formatting js" httpdocs/dir1/dir2/fileirDir3

这将包括明确忽略(根本不跟踪)的文件,包括 bak_admin.abc.php
即使正确设置了 .gitignore,shell(不是 git)也会将 bak_admin.abc.php 传递给 git commit 命令,导致

error: pathspec 'httpdocs/dir1/dir2/bak_admin.abc.php' did not match any file(s) known to git.

解决方法:不要使用'*'

git commit -m "formatting js" httpdocs/
git commit -m "formatting js" httpdocs/dir1/dir2/