Here is my system dialogue:
unrollme-dev-dan:views Dan$ git reset --hard HEAD
HEAD is now at 3f225e9 Fix scan titles
unrollme-dev-dan:views Dan$ git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: app/signup/finish.html
# modified: app/signup/scan.html
#
I have autocrlf set to false:
unrollme-dev-dan:unroll-website Dan$ git config core.autocrlf
unrollme-dev-dan:unroll-website Dan$
unrollme-dev-dan:unroll-website Dan$ git config --global core.autocrlf
unrollme-dev-dan:unroll-website Dan$
And I don't have any .gitattributes files messing this up:
unrollme-dev-dan:unroll-website Dan$ find . -name .gitattributes
[ only results are in different directory tree ]
This is caused by a .gitattributes
one level up as pointed out in answer below.
When I do an od -c
on the files it shows \r\n
. I don't know what they "should" be, presumably, they should end in \n
and that is why the diff is showing. But what I don't understand is how these files could possibly be modified on checkout even with autocrlf
false.
What can cause git modifying a file on checkout besides autocrlf?
This problem can be caused by gitattributes' text option https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html
This problem can be fixed by temporarily editing your .gitattributes
file within your project folder.
change * text=auto
to #* text=auto
make the necessary changes to files line endings and push your commit. You can then enable it again after the change has been made, or alternatively select one of the other options that may better suit your project.
I didn't have a gitattributes file as is mentioned in the accepted answer, it was a file permissions problem in my case. To see if this is your problem check the changed files' differences with git diff, e.g.:
git diff path/to/file.html
If the only change you see is old mode/new mode, it's likely a permissions problem. You can tell git to ignore file permission changes using:
git config core.filemode false
or
git config --global core.filemode false
(depending on how you use git).
I recently switched from using Cygwin git to git for Windows for performance reasons, plus so that TortoiseGit works properly, this may be the reason permissions were thrown off in my case.
References:
来源:https://stackoverflow.com/questions/15684197/git-files-modified-after-checkout-reset-hard-etc-even-though-autocrlf-is-se