Phantom local changes displayed in Git

I have a very strange git error that doesn't understand me at all. This is not the main blocker, but it is extremely annoying to work all the time.

I have a working copy of the repository, and in the specified working copy, every time I switch from one branch to another, git tells me that after the switch completes, I have local modifications. A few more details:

  • This is on Windows
  • Git status shows the file as changed (each line is changed, see the attached screenshot for an example)
  • Apart from comparison, there are no differences; file encoding and line endings are the same, both files have the same number of bytes.
  • The strange thing is: I cannot reset the changes, whatever they are. Even deleting a file and then resetting the delete results in a new file that was supposedly changed.

What could be here? I thought this might be due to file attributes, but I don't know how to check this.

Screenshot of phantom git changes


Update: VonC was right that these were the line endings that were the problem. More specifically, if you are core.autocrlfset to true, but all the files in the repository that were previously associated with the end of the Windows line, you will see this problem. The reason this cannot be done for reset is because checking the file modifies it, since git works, that your working copy of the file is different from what it will look like if you have to do it now. I'm embarassing.

, , , Unix, , , , . : git filter-branch, , Russ Egan, .

+4
2

, ( ), :

git config --global core.autocrlf false

eol (end-of-line), ( msysgit).
.gitattributes - , eol.

. "git LF CRLF" .

+1

...

phantom, , .

:
( git "", )

git config --global core.autocrlf false
git config --local core.autocrlf false

, - .gitattributes , , autocrlf , . , .gitattributes, , .

0

Source: https://habr.com/ru/post/1534415/


All Articles