Reputation: 1431
I searched for an answer to this in Google but came up with nothing.
In Windows, I configured git via eclipse. When I try to commit a modified file to my branch via Team --> commit, it shows only the modified lines as changed, but whenever my lead tries to merge the change to the branch it shows the whole file as changed
Can anyone suggest to me what is going to wrong?
Thanks in advance.
Upvotes: 8
Views: 10379
Reputation: 31
Following has fixed the problem for me in Eclipse
Upvotes: 3
Reputation: 19035
This is most likely a line ending issue. Windows ends lines with CRLF
, whereas other operating systems end them with LF
. When files in a repository are changed by people using both types of operating systems, the fact that their respective editors change every line of a file to their particular flavor of line endings causes the behavior you are seeing.
Even if everyone on the team is using Windows, Git's attempts to "fix" this issue can also cause this issue to come up. This is because one way to tell Git to fix this issue is to set core.autocrlf
to true. Doing this will cause Git to convert every CRLF
to a LF
on commit, and every LF
to a CRLF
on checkout. The problem is when different developers of the project have their core.autocrlf
set to different values. So let's say you have core.autocrlf
set to true, and another developer has it set to false. When you commit a file, Git will do the line ending conversion, and the repo will contain LF
line endings. When the other developer checks out the file, no conversion will be done, and therefore every one of the lines in their local file (which have CRLF
) will be different than in the repository.
The solution to this is to not rely on core.autocrlf
to determine whether any of this normalization is done, since that can vary by machine. Instead, you want to have a .gitattributes
file in your repo's root directory that determines whether normalization is done. What you want in there depends on if your whole team is using Windows or not.
If your whole team uses Windows: In this case, I would recommend disabling line ending normalization, as there is no need for it. To do this, put * -text
in your .gitattributes
file.
If your team uses other OSs in addition to Windows: In this case you do want line endings to be normalized. To make it consistent for everyone, put * text=auto
in your .gitattributes
file.
Upvotes: 12