-1

I found this conflict upon a Git merge, and it seemed due to whitespace or a comment or something (it could be because I am switching between a Mac and Windows machine when doing 'git pull' from Github):

<<<<<<< HEAD
    //TODO: ejs.update()
=======
>>>>>>> 1dafd696d98769c5ce15d3378cb8df19e42fe2f9

I also got this one in my .gitignore file

<<<<<<< HEAD
.idea/
=======
.idea/
>>>>>>> 1dafd696d98769c5ce15d3378cb8df19e42fe2f9

is there a way to tell Git to ignore white-space for automatic git merges? or am I experiencing another problem (perhaps due to switching between Mac and Windows).

  • 3
    possible duplicate of [Merging without whitespace conflicts](http://stackoverflow.com/questions/9776527/merging-without-whitespace-conflicts) – GolezTrol Jun 27 '15 at 22:39
  • but I add a twist - switching between Mac and Windows development machines –  Jun 27 '15 at 22:41
  • also, I gitignored the .gitignore file, for some reason I assumed that gitignore automatically ignored that file, but I guess not. –  Jun 27 '15 at 22:42
  • 1
    That is a twist you should have mentioned. Mac, being Unix-bases, has different line endings than Windows, and is most likely the cause of your problems. The best solution if to configure your editors to always use the same line endings, otherwise you will have these merge issues on each commit. – GolezTrol Jun 27 '15 at 22:45
  • 1
    @Olegzandr, your `.gitignore` file *should not* be ignored. Put project ignores in there and commit the file. Personal ignores that you don't want to share should go into `.git/info/exclude`. – ChrisGPT was on strike Jun 27 '15 at 23:54

1 Answers1

1

Beyond the linked answer, your switching between environments is certainly the issue, since the CRLF newline will not look the same to git as the LF newline. GitHub has a good article on it.

The short answer is that you need to automatically convert line endings when committing by setting core.autocrlf by machine. You can also set it per repository. The way that I typically deal with it is to give my Windows machines true:

git config --global core.autocrlf true

And let Mac and Linux be input instead of true. This will cause all commits on Windows to be convert to LF (and will output some warnings) and will leave them alone on the others. Your repository will then be in Unix-style eol.

Jeremy Fortune
  • 2,459
  • 1
  • 18
  • 21