2

I have a git repository which is hosted in bit bucket. I use source tree to work with git. I have a pull request in which some files appear as modified, but the contents of the file are essentially unchanged. I noticed that when I compared the two branches in bit bucket and source tree. This is what the diff looks like in those tools :

-j1
-j2
-j3
+j1
+j2
+j3

This is very confusing because (1) it makes it appear as though there are many changes, even though there are no real changes, and (2) any changes to a particular line could be missed if you have a huge file (unlike the small one I showed above.)

But, when I compared the two branches in command line (git diff branch1 branch2), I saw that there is a ^M character at the end of each line in one branch which is responsible for the difference.

How do I ensure that end of line characters like ^M, TAB, SPACE etc. get removed in git so that we can avoid confusion in pull requests ? Also, how do I find out why these EOL characters got added in the first place ?

6
  • Use better, smarter tools to compare (Beyond Compare, etc.), also use .gitattributes
    – ddbug
    Commented Oct 18, 2019 at 1:41
  • @ddbug - ok. but, I need to prevent this problem in the first place because it will show up in the git host. I have no control over that host. So, I need a better fix. Commented Oct 18, 2019 at 1:43
  • 1
    Then use a smarter editor which saves files in your preferred way, defined via editorconfig for example.
    – ddbug
    Commented Oct 18, 2019 at 1:49
  • 1
    @Borat - I have seen this issue while using both windows and Linux to change code. I had the clone of a repo created in windows machine and also in a VM based on redhat Linux sometime back. This helped me get it resolved. Commented Oct 18, 2019 at 2:24
  • 1
    Do not try to use config for this.... this is the old way to work around this problem. Try .gitattributes file instead.
    – eftshift0
    Commented Oct 18, 2019 at 3:08

1 Answer 1

1

Try first

git config --global core.autocrlf false

Then clone again, and make sure there is no diff.
That will ensure there is no "automagic" eol conversion.

Then you can add in a .gitattributes eol directives (example here)

Not the answer you're looking for? Browse other questions tagged or ask your own question.