Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GIT complains about randomly changed files when switching branches

Tags:

git

whitespace

Starting from

git status
# On branch master
nothing to commit, working directory clean

and then switching to another branch

git checkout somebranch

after switching to a new branch and running a git status git will sometimes complain about randomly changed files. If i diff the files with git diff it will display the whole files first with all lines being removed and then added again

- someline
- someotherline
+ someline
+ someotherline

Then running a git diff --ignore-space-at-eol . will not show any files changed leading me to believe there is line ending issues somewhere inside the git repo because if I do a binary comparison of the files with my merge tool of choice (Beyond Compare) it tells me that the files are binary the same even though git complains about them being different, hell I even did a hex compare and they where indeed identical, so why does git see them as changed?

The repository was on old svn repository that was converted by following the github guidelines https://help.github.com/articles/importing-from-subversion and after that we added our .gitattributes file to the solution which looks like this:

# .gitattributes
# Auto detect text files and perform LF normalization
* text=auto

# Custom for Visual Studio
*.cs     diff=csharp
*.sln    merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union

# Standard to msysgit
*.doc    diff=astextplain
*.DOC    diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot  diff=astextplain
*.DOT  diff=astextplain
*.pdf  diff=astextplain
*.PDF    diff=astextplain
*.rtf    diff=astextplain
*.RTF    diff=astextplain

After adding the .gitattributes file we also followed githubs guide to fixing line endings from https://help.github.com/articles/dealing-with-line-endings

Everyone on the team is running on windows, everyone on the team is using core.autocrlf=true and everyone is using at least

git --version
git version 1.8.3.msysgit.0

What could be wrong here? The files git complains about is completely random and it happens for everyone across the team. Also it is impossible to revert the files it complains about with a git checkout file-that-hasnt-really-changed.

like image 327
Thomas Schmidt Avatar asked Oct 03 '13 05:10

Thomas Schmidt


Video Answer


1 Answers

I had the same problem after adding the default .gitattributes file generated by Visual Studio in my depot. You can fix it by commenting out the following line in .gitattributes:

# * text=auto

Commit this file only and all the other spurious changed files will now disappear from your list of local changes.

Note: The auto option instructs git to store all files with LF line ending internally. When you checkout the files the line endings are converted back to CRLF so we you then run git diff it sees differences between the LF from the depot and CRLF from the checkout version. Seems like a bug to me.

like image 177
luwei Avatar answered Oct 27 '22 14:10

luwei