Why is git ignoring my changed file?

2019-03-15 01:40发布

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?

标签: git gitignore
9条回答
干净又极端
2楼-- · 2019-03-15 02:18

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/

查看更多
疯言疯语
3楼-- · 2019-03-15 02:19

Also make sure that you have not manually updated the index to assume that the changed file(s) are unchanged like so:

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

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 or exclude files.

If you've told git to assume the file is unchanged, you will have to:

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

or just re-clone the repo like I ended up doing before I remembered what I had done...

查看更多
孤傲高冷的网名
4楼-- · 2019-03-15 02:21

There are two general reasons why Git will ignore a file: gitignore and submodules.

To be more specific, the following conditions will cause Git to ignore a file when 'git add' is invoked:

  1. The file matches a pattern in $GIT_DIR/exclude.
  2. The file matches a pattern in a .gitignore file inside the repo.
  3. The file matches a pattern in a user-specific .gitignore file (specified by 'git config --global core.excludesfile').
  4. The file is part of a submodule.

More info can be found in another SO question:

Unable to track files within Git submodules

查看更多
beautiful°
5楼-- · 2019-03-15 02:21

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.

查看更多
Luminary・发光体
6楼-- · 2019-03-15 02:24

You check your global git ignore file?

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

If either of those return a file as their value, look in that file.

查看更多
走好不送
7楼-- · 2019-03-15 02:28

Check using

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

if the file is truly not excluded (there are other exclude files than only .gitignore).

查看更多
登录 后发表回答