为什么 git 忽略我更改的文件?
我对 git 工作目录中的文件进行了任意更改。
git status
无法识别文件已更改。
git add /path/to/file
无效。
git add -f /path/to/file
无效。
git status /path/to/file
显示“要提交的更改”存储桶中的文件。
为了确定起见,我删除了 .gitignore 文件。上述任何行为均不会改变。
我已经完成了 git reset --hard ,重新进行了更改。上述任何行为均不会改变。
这里可能发生了什么?
I make an arbitrary change to a file within my git working directory.
git status
does not recognized that the file has changed.
git add /path/to/file
has no effect.
git add -f /path/to/file
has no effect.
git status /path/to/file
shows the file as in the 'changes to be committed' bucket.
I removed my .gitignore file, just to be sure. No change to any of the above behaviors.
I have done git reset --hard
, re-made my change. No change to any of the above behaviors.
What could be going on here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
还要确保您没有手动更新索引以假设更改的文件未更改,如下所示:
尽管听起来很愚蠢,但我这样做了,然后几天后对文件进行了更改,但无法弄清楚为什么git 没有跟踪它。我尝试了上述所有建议,但一直在抓狂,因为更改的文件未在任何 .gitignore 或 except 文件中列出。
如果你告诉 git 假设文件未更改,你将不得不:
或者只是重新克隆存储库,就像我在记起自己所做的事情之前所做的那样......
Also make sure that you have not manually updated the index to assume that the changed file(s) are unchanged like so:
As dumb as it sounds I did that, then a few days later made changes to the file and could not figure out why git was not tracking it. I tried all of the above suggestions, and kept pulling my hair out b/c the changed file was not listed in any
.gitignore
orexclude
files.If you've told git to assume the file is unchanged, you will have to:
or just re-clone the repo like I ended up doing before I remembered what I had done...
结果我在我的文件中添加了
skip-worktree
[1]然后忘记了。您可以使用以下命令撤消此操作:
ls-files
和-v
在我的案例中显示了文件的状态:字母
git ls-files -v
> 将使用 are 前缀并表示:识别您的问题
该文件是否被 git 忽略?
如果列出了该文件,则说明某处有一条忽略规则将其排除在外。[2] [3] 在以下文件之一中找到它:
该文件是否标记为
assume-unchanged
如果文件以小写字母为前缀,则会使用
assume-unchanged
进行标记。修复方法:文件是否标记为
skip-worktree
如果文件前缀为
S
,则它标记为skip-worktree
。修复它:Turns out I added
skip-worktree
on my file [1]and forgot. You can undo this with:
ls-files
with-v
revealed the status of the file in my case:The letters
git ls-files -v
will prefix with are and mean:To identify your issue
Is the file ignored by git?
If the file is listed, there is an ignore rule somewhere that is excluding it.[2] [3] Find it in one of these files:
Is the file flagged
assume-unchanged
If the file is prefixed with a lower case letter, it is flagged with
assume-unchanged
. Fix it with:Is the file flagged
skip-worktree
If the file is prefixed with
S
, it is flagged withskip-worktree
. Fix it with:Git 忽略文件的一般原因有两个:
gitignore
和子模块
。更具体地说,以下条件将导致 Git 在调用“
git add
”时忽略文件:$GIT_DIR/exclude
中的模式匹配。.gitignore
文件(由“git config --global core.excludesfile
”指定)中的模式匹配。更多信息可以在另一个SO问题中找到:
无法跟踪文件在 Git 子模块内
There are two general reasons why Git will ignore a file:
gitignore
andsubmodules
.To be more specific, the following conditions will cause Git to ignore a file when '
git add
' is invoked:$GIT_DIR/exclude
..gitignore
file inside the repo..gitignore
file (specified by 'git config --global core.excludesfile
').More info can be found in another SO question:
Unable to track files within Git submodules
检查使用
文件是否确实未被排除(除了
Check using
if the file is truly not excluded (there are other exclude files than only .gitignore).
你检查你的全局 git 忽略文件吗?
如果其中任何一个返回一个文件作为其值,请查看该文件。
You check your global git ignore file?
If either of those return a file as their value, look in that file.
如果您的文件位于“要提交的更改”存储桶中,则 git 已经识别该更改并将提交它!它已经在索引中。否则,它将位于“已更改但未更新”存储桶中。
:)
希望这有帮助/
if your file is in the 'Changes to be committed' bucket then git already recognized the change and is going to commit it! Its in the index already. Otherwise it would be in the 'Changed but not updated' bucket.
:)
Hope this helps/
您确定您的文件没有被父目录中的某些 .gitignore 文件排除吗?
Are you sure that your file is not excluded by some of the .gitignore files in parent directories?
完成 git add 后,您是否进行了提交,以便它实际上位于存储库中并且可以与(更改的)工作副本进行比较?
After you did git add, did you do a commit so it's actually in the repo and can be compared to the (changed) working copy?
检查从相关文件到项目根目录的每个父目录中是否有 .gitignore 文件。
某些项目使用多个 .gitignore 文件,每个文件都位于自己的目录中,而不是根目录中的单个 .gitignore 文件。
Check each parent directory from the file in question to the project root for .gitignore files.
Some projects use several .gitignore files, each in its own directory, instead of a single .gitignore in the root.