17

我对 git 工作目录中的文件进行了任意更改。

git status无法识别文件已更改。

git add /path/to/file没有效果。

git add -f /path/to/file没有效果。

git status /path/to/file将文件显示为“要提交的更改”存储桶中的文件。

为了确定,我删除了我的 .gitignore 文件。上述任何行为均无变化。

我已经完成了git reset --hard,重新做出了改变。上述任何行为均无变化。

这里会发生什么?

4

9 回答 9

32

还要确保您没有手动更新索引以假设更改的文件未更改,如下所示:

git update-index --assume-unchanged path/to/file

尽管听起来很愚蠢,但我这样做了,几天后对文件进行了更改,无法弄清楚为什么 git 没有跟踪它。我尝试了上述所有建议,并不断拉扯我的头发 b/c 更改的文件未在任何.gitignoreexclude文件中列出。

如果你告诉 git 假设文件没有改变,你必须:

git update-index --no-assume-unchanged path/to/file

或者只是在我记得我做了什么之前像我最终做的那样重新克隆回购......

于 2014-01-06T20:51:13.323 回答
21

原来我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忽略了文件吗?

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
于 2015-06-26T14:43:55.957 回答
9

Git 忽略文件的一般原因有两个:gitignoresubmodules.

更具体地说,以下情况将导致 Git 在git add调用 ' ' 时忽略文件:

  1. 该文件与$GIT_DIR/exclude.
  2. 该文件与.gitignorerepo 内的文件中的模式匹配。
  3. 该文件与用户特定.gitignore文件(由“ git config --global core.excludesfile”指定)中的模式匹配。
  4. 该文件是子模块的一部分。

更多信息可以在另一个 SO 问题中找到:

无法跟踪 Git 子模块中的文件

于 2009-08-25T16:40:42.157 回答
6

检查使用

$ git ls-files --exclude-standard --ignore

如果该文件确实没有被排除(除了.gitignore之外还有其他排除文件)。

于 2009-08-27T09:59:23.690 回答
4

你检查你的全局 git 忽略文件?

git config --global --get-all core.excludesfile
git config --system --get-all core.excludesfile

如果其中任何一个返回文件作为其值,请查看该文件。

于 2009-08-25T16:34:40.610 回答
2

如果您的文件在“要提交的更改”存储桶中,那么 git已经识别出更改并将提交!它已经在索引中。否则它将在“已更改但未更新”存储桶中。

:)

希望这可以帮助/

于 2009-08-25T16:48:28.773 回答
1

您确定您的文件没有被父目录中的某些 .gitignore 文件排除在外吗?

于 2009-08-25T16:36:34.397 回答
0

在你做了 git add 之后,你是否做了一个提交,所以它实际上在 repo 中并且可以与(更改的)工作副本进行比较?

于 2009-08-25T16:40:38.927 回答
0

检查从相关文件到项目根目录的每个父目录是否有 .gitignore 文件。

一些项目使用多个 .gitignore 文件,每个文件都在自己的目录中,而不是根目录中的单个 .gitignore。

于 2014-07-14T23:04:54.373 回答