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.
As you edit files, Git sees them as modified, because you've changed them since your last commit. As you work, you selectively stage these modified files and then commit all those staged changes, and the cycle repeats.
Find what file changed in a commit To find out which files changed in a given commit, use the git log --raw command. It's the fastest and simplest way to get insight into which files a commit affects.
For every tracked file, Git records information such as its size, creation time and last modification time in a file known as the index. To determine whether a file has changed, Git compares its current stats with those cached in the index. If they match, then Git can skip reading the file again.
Enter git add --all at the command line prompt in your local project directory to add the files or changes to the repository. Enter git status to see the changes to be committed. Enter git commit -m '<commit_message>' at the command line to commit new files/changes to the local repository.
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.
Following has fixed the problem for me in Eclipse
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With