我有一个 git 仓库,它忽略了图像文件以及其他一些文件,但是我的 .gitignore
文件只忽略了一个 config.php
文件。是否有某个全局忽略文件我找不到?现在我必须指定文件才能添加它们,这让我收到以下警告:
以下路径被您的 .gitignore 文件之一忽略。
我的 ~/.gitconfig
文件中只有我的电子邮件地址。
git check-ignore
使用git check-ignore
命令来调试你的.gitignore文件(排除文件)。
例如:
$ git check-ignore -v config.php
.gitignore:2:src config.php
以上输出详细描述了每个给定路径名(包括行号)的匹配模式(如果有的话)。
因此,也许不是忽略了您的文件扩展名,而是整个目录被忽略了。
返回格式如下:
<source> <COLON> <linenum> <COLON> <pattern> <HT> <pathname>
您可以使用以下命令来打印您的.gitignore
文件在用户HOME和仓库文件夹中:
cat ~/.gitignore "$(git rev-parse --show-toplevel)"/.gitignore "$(git rev-parse --show-toplevel)"/.git/info/exclude
或者,您可以使用git add -f
命令,该命令允许添加被忽略的文件。
更多详情请参考:man gitignore
,man git-check-ignore
。
git check-ignore [选项] pathname…
git check-ignore [选项] --stdin
#Git正在忽略不在gitignore中的文件
,然后是此答案的URL。 - Karl你可能会想知道,你的git配置文件可以包含一个core.excludesfile,这是一个忽略额外模式的路径文件。你可以通过运行以下命令(在有问题的git存储库中)来查看是否有这样的配置:
值得一提的是,你的git配置文件可以包含一个core.excludesfile属性,指向一个包含额外被 Git 忽略的模式列表的文件。如果您在问题存储库中执行以下命令,则可以查看是否存在此类配置:
git config core.excludesfile
如果打印出文件路径,请查看该文件的内容以获取更多信息。Icon?
被忽略的问题。 - Justin Skiles请看一下这些内容:
你是否查找了其他.gitignore文件,因为可能存在许多这样的文件。
另外,请查看REPO/.git/config以查看是否有任何内容。
Repo排除本地每个存储库规则可以添加到您存储库中的.git/info/exclude文件中。这些规则不会与存储库一起提交,因此它们不会与其他人共享。此方法可用于局部生成的文件,您不希望其他用户生成,例如由编辑器创建的文件。
我遇到了相同的问题 - 在 git 中出现以下错误,该目录被忽略:
➭ git add app/views/admin/tags/
The following paths are ignored by one of your .gitignore files:
app/views/admin/tags
Use -f if you really want to add them.
fatal: no files added
我终于弄清楚了我的问题出在~/.gitignore_global
的一行代码上:
TAGS
该路径为app/views/admin/tags
。我通过在全局的gitignore文件中添加一个前导斜杠来解决了这个问题。
/TAGS
然后git重新开始跟踪我的目录。
help
的目录,但它被忽略了。幸运的是,我很快就找到了你的答案。 - Abdul Sadik Yalcin对我来说,我的~/.gitignore_global文件中意外地有一个通配符。也许可以在那里检查一下?
/srv/bootstrap/
工作
srv/bootstrap/
另一个尝试的方法:我有一个目录B,它有自己的.git
嵌套在我的项目目录A下(但不是作为子模块)。我对B进行了一些更改,并希望将其变成一个真正的子模块。我认为git A自动忽略B,因为它包含自己的存储库(请参见无子模块的嵌套git存储库? )。我重命名了B文件夹,并尝试将其再次克隆为子模块,这会带来误导性的“被.gitignore忽略”的错误消息。解决方案是从B中删除.git
。
.gitignore
: skip-worktree
和 assume-unchanged
文件可能因以下原因被忽略:
.gitignore
(所有内容的组合)git update-index --skip-worktree
git update-index --assume-unchanged
此外,如果文件在 .gitignore
中并且已经在索引 / 缓存中暂存,则可以取消忽略该文件。
要检查上述列出的情况:
对于两种 .gitignore
排除的情况,请比较以下命令的输出:
git check-ignore --verbose --non-matching --no-index file1 file2 file3
git check-ignore --verbose --non-matching file1 file2 file3
git ls-files file1 file2 file3 | grep -E '^S'
git ls-files file1 file2 file3 | grep -E '^[[:lower:]]'
以下别名将涵盖上述所有情况:
ignore = !"bash -c 'diff --unified=999999999 --color=always <(echo a; git check-ignore --verbose --non-matching --no-index . \"$@\") <(echo b; git check-ignore --verbose --non-matching . \"$@\")' - \"$@\" | tail -n+7; git hidden \"$@\" # Show ignore status of arguments. Files included by index are tagged with prepended '+'."
hidden = !"git ls-files -v -- \"$@\"| grep -E '^(S|[[:lower:]])' # S means update-index --skip-worktree, and lower first letter means --assume-unchanged."
注释和最后的"
是要复制到你的.gitconfig
文件中的一行内容。
用法:
git ignore file1 file2 file3
当执行git submodule add
命令时,如果之前的一个git命令崩溃并留下了锁文件,你也会收到来自git的错误消息(这可能发生在你使用包含git命令且没有注意到崩溃的自定义脚本时)。
如果条件没有改变(git submodule add
会继续抱怨你的 .gitignore
文件有问题),而你执行git commit
命令,则会看到另一个错误报告:
$ git commit -a
fatal: Unable to create '..../.git/index.lock': File exists.
If no other git process is currently running, this probably means a
git process crashed in this repository earlier. Make sure no other git
process is running and remove the file manually to continue.
rm .git/index.lock
解决了这个问题。(这个问题出现在git版本2.1.0.9736上,可能会在未来的git版本中得到修复。)