Git files modified after checkout, reset --hard, e

2019-02-04 13:48发布

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?

2条回答
闹够了就滚
2楼-- · 2019-02-04 14:06

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.

查看更多
祖国的老花朵
3楼-- · 2019-02-04 14:31

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:

  1. How do I remove files saying "old mode 100755 new mode 100644" from unstaged changes in Git?
查看更多
登录 后发表回答