Me and my co-workers have always struggled with this issue. It is quite well documented (some links at the end of the page), but so far I haven't been able to fix this. We code in c# using visual studio 2013.
Whenever we merge two branches, we have loads of "changes", in which a file is fully replaced by an identical one. From what I could read online, I am almost sure it is due to a problem with line endings.
The following answer is the one that helped me the most. The first time I followed the steps, it could only find a single file to be normalised, namely the .gitattributes file. But then I replaced that file by the file below as a first step, and the files expected to be normalised were found. This was all done in my local branch.
# Set the default behaviour, in case people don't have core.autocrlf set.
* text=auto
# Explicitly declare the text files you want to always be normalised and converted
# to native line endings on checkout.
*.cs text
*.json text
*.html text
*.csproj text
# Declare files that will always have CRLF line endings on checkout.
*.sln text eol=crlf
# Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary
*.gif binary
I went through the next steps, and I had the expected messages (below) after typing the command: "git add -u"
message:
warning: CRLF will be replaced by LF in (...)
However, when I switched to the master branch and updated from my local branch, several files were, once again, replaced. I tried to create the same .gitattributes file in the master branch and follow the steps again, but the files that were supposed to be normalised were not found after the "git status" command, and the merge always performed as before, replacing several files by identical ones.
What I am doing wrong?