Git 说我的 .gitignore 有变化但是 "git status" 显示 "nothing to commit"

Git saying there are changes to my .gitignore but "git status" shows "nothing to commit"

目前正在 master 的一个分支上工作,并向 .gitignore 添加了一些内容。我提交了所有更改并尝试检查另一个分支,但我得到:

error: Your local changes to the following files would be overwritten by checkout:
  .gitignore
Please, commit your changes or stash them before you can switch branches.
Aborting

当我运行git status时,我得到:

On branch feature/blahblah
nothing to commit, working directory clean

这是否意味着 git 没有跟踪我的 .gitignore 文件?如果是这样,我如何让它识别文件?

您是否偶然在 .gitignore 文件中添加了 .gitignore 行,以使其忽略自身?如果是这样,请将其删除;最好不要忽略.gitignore文件。除了 .gitignore 之外的其他可能负责的地方是您的全局 core.excludesfile 设置,或者您存储库中的 .git/info/excludes 文件(不会被签入)。这些都不是一般的好做法,但某些特定情况可能需要它们(例如,一个开发人员使用与项目中其他人不同的编辑器,因此他需要一组不同的忽略文件),因此这些选项可用。有关详细信息,请参阅 https://help.github.com/articles/ignoring-files/

这很可能是你的问题。

所以,如果这发生在任何人身上,不知何故,运行:

git rm --cached .gitignore