Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git files modified after checkout, reset --hard, etc. even though autocrlf is set to false

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?

like image 817
djechlin Avatar asked Mar 28 '13 14:03

djechlin


People also ask

Why does git show that all my files changed when I didn't change them?

These changes mean that metadata about your file changed, however the content of your file did not. If you're working in a group, this may start to intefere with pushes or just add noise to your commits.

Does git reset hard remove staged changes?

Git Reset A Specific File The changes it contains will still be present in the working directory. The --soft , --mixed , and --hard flags do not have any effect on the file-level version of git reset , as the staged snapshot is always updated, and the working directory is never updated.

When running git reset the affected files will change state?

Comparatively, git reset , moves both the HEAD and branch refs to the specified commit. In addition to updating the commit ref pointers, git reset will modify the state of the three trees. The ref pointer modification always happens and is an update to the third tree, the Commit tree.


1 Answers

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.

like image 186
Cris Favero Avatar answered Oct 20 '22 10:10

Cris Favero