我对 git 工作目录中的文件进行了任意更改。
git status
无法识别文件已更改。
git add /path/to/file
没有效果。
git add -f /path/to/file
没有效果。
git status /path/to/file
将文件显示为“要提交的更改”存储桶中的文件。
为了确定,我删除了我的 .gitignore 文件。上述任何行为均无变化。
我已经完成了git reset --hard
,重新做出了改变。上述任何行为均无变化。
这里会发生什么?
还要确保您没有手动更新索引以假设更改的文件未更改,如下所示:
git update-index --assume-unchanged path/to/file
尽管听起来很愚蠢,但我这样做了,几天后对文件进行了更改,无法弄清楚为什么 git 没有跟踪它。我尝试了上述所有建议,并不断拉扯我的头发 b/c 更改的文件未在任何.gitignore
或exclude
文件中列出。
如果你告诉 git 假设文件没有改变,你必须:
git update-index --no-assume-unchanged path/to/file
或者只是在我记得我做了什么之前像我最终做的那样重新克隆回购......
原来我skip-worktree
在我的文件中添加了[1]
git update-index --skip-worktree path/to/file
并忘记了。您可以使用以下方法撤消此操作:
git update-index --no-skip-worktree path/to/file
ls-files
在我的案例中-v
揭示了文件的状态:
git ls-files -v | grep path/to/file
S path/to/file
这些字母git ls-files -v
将以 are 为前缀并表示:
# H: cachead
# S: skip-worktree
# M: unmerged
# R: removed/deleted
# C: modified/changed
# K: to be killed
# ?: other
# lowercase letter: assume-unchanged
git check-ignore * **/* | grep path/to/file
git ls-files --exclude-standard --ignore
如果列出了该文件,则在某处有一条忽略规则将其排除在外。[2] [3]在以下文件之一中找到它:
less .gitignore
less ~/.gitignore
less %USERPROFILE%\.gitignore # <- Probably the same file as the above one
less $( git config --global core.excludesfile )
less $( git config --system core.excludesfile )
less ${GIT_DIR:-.git}/exclude
assume-unchanged
git ls-files -v | grep path/to/file
如果文件以小写字母为前缀,则标记为assume-unchanged
. 修复它:
git update-index --no-assume-unchanged path/to/file
skip-worktree
git ls-files -v | grep path/to/file
如果文件以 为前缀S
,则用 标记skip-worktree
。修复它:
git update-index --no-skip-worktree path/to/file
Git 忽略文件的一般原因有两个:gitignore
和submodules
.
更具体地说,以下情况将导致 Git 在git add
调用 ' ' 时忽略文件:
$GIT_DIR/exclude
..gitignore
repo 内的文件中的模式匹配。.gitignore
文件(由“ git config --global core.excludesfile
”指定)中的模式匹配。更多信息可以在另一个 SO 问题中找到:
你检查你的全局 git 忽略文件?
git config --global --get-all core.excludesfile
git config --system --get-all core.excludesfile
如果其中任何一个返回文件作为其值,请查看该文件。
如果您的文件在“要提交的更改”存储桶中,那么 git已经识别出更改并将提交!它已经在索引中。否则它将在“已更改但未更新”存储桶中。
:)
希望这可以帮助/
您确定您的文件没有被父目录中的某些 .gitignore 文件排除在外吗?
在你做了 git add 之后,你是否做了一个提交,所以它实际上在 repo 中并且可以与(更改的)工作副本进行比较?
检查从相关文件到项目根目录的每个父目录是否有 .gitignore 文件。
一些项目使用多个 .gitignore 文件,每个文件都在自己的目录中,而不是根目录中的单个 .gitignore。