Why do I have a file that's always modified?
Internally, Git always stores file names as sequences of bytes and doesn't
perform any encoding or case folding.
However, Windows and macOS by default
both perform case folding on file names.
As a result, it's possible to end up
with multiple files or directories whose names differ only in case.
Git can
handle this just fine, but the file system can store only one of these files,
so when Git reads the other file to see its contents, it looks modified.
It's best to remove one of the files such that you only have one file. You can
do this with commands like the following (assuming two files AFile.txt
and
afile.txt
) on an otherwise clean working tree:
$ git rm --cached AFile.txt
$ git commit -m 'Remove files conflicting in case'
$ git checkout .
This avoids touching the disk, but removes the additional file.
Your project
may prefer to adopt a naming convention, such as all-lowercase names, to avoid
this problem from occurring again; such a convention can be checked using a
pre-receive
hook or as part of a continuous integration (CI) system.
It is also possible for perpetually modified files to occur on any platform if a
smudge or clean filter is in use on your system but a file was previously
committed without running the smudge or clean filter.
To fix this, run the
following on an otherwise clean working tree:
$ git add --renormalize .
mv Foo.js foo.js
后,git status
没有显示Foo.js
已被删除吗? - Arkadiusz Drabczykgit status
时,它会显示没有文件被删除。但是,当我设置git config core.ignorecase false
时,只有文件foo.js
需要添加(而Foo.js
则不会出现在任何地方)。 - Jason Jarrett