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条回答
Melony?
2楼-- · 2019-03-15 02:35

Turns out I added skip-worktree on my file [1]

git update-index --skip-worktree path/to/file

and forgot. You can undo this with:

git update-index --no-skip-worktree path/to/file

ls-files with -v revealed the status of the file in my case:

git ls-files -v | grep path/to/file
S path/to/file

The letters git ls-files -v will prefix with are and mean:

# H: cachead
# S: skip-worktree
# M: unmerged
# R: removed/deleted
# C: modified/changed
# K: to be killed
# ?: other
# lowercase letter: assume-unchanged

To identify your issue

Is the file ignored by git?

git check-ignore * **/* | grep path/to/file
git ls-files --exclude-standard --ignore

If the file is listed, there is an ignore rule somewhere that is excluding it.[2] [3] Find it in one of these files:

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

Is the file flagged assume-unchanged

git ls-files -v | grep path/to/file

If the file is prefixed with a lower case letter, it is flagged with assume-unchanged. Fix it with:

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

Is the file flagged skip-worktree

git ls-files -v | grep path/to/file

If the file is prefixed with S, it is flagged with skip-worktree. Fix it with:

git update-index --no-skip-worktree path/to/file
查看更多
叛逆
3楼-- · 2019-03-15 02:40

Are you sure that your file is not excluded by some of the .gitignore files in parent directories?

查看更多
唯我独甜
4楼-- · 2019-03-15 02:42

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?

查看更多
登录 后发表回答