1

I often get conflicts while pulling (merging) in git over differences in newlines at the end of the file.

The conflict comes out looking like this:

diff --cc httpdocs/about/faq.php
index 0ae3963,b5eb519..0000000
--- a/httpdocs/about/faq.php
+++ b/httpdocs/about/faq.php
@@@ -212,4 -211,4 +212,8 @@@ $_SESSION['activePage'] = 'about'
        </div><!-- end wrap -->

 -<?php require RESOURCE_PATH."page_elements".SLASH."footer.php"; ?>
++<<<<<<< HEAD
 +<?php require RESOURCE_PATH."page_elements".SLASH."footer.php"; ?>
++=======
++<?php require RESOURCE_PATH."page_elements".SLASH."footer.php"; ?>
++>>>>>>> 564e069cccfad98f818ec878a3b2526fd9430f8a

Worse; after I manually resolve the files and add the conflicted files, there doesn't seem to be anything to commit (in relation to the end of the files), so when I do a pull again, I get the exact same conflicts. Any solutions?

EoghanM
  • 25,161
  • 23
  • 90
  • 123
  • After you resolve the files and add, you should be able to commit. What are the exact commands you ran? – Josh Lee Sep 08 '11 at 22:25

1 Answers1

3

These differences are resulting form the fact that different OS's have a different idea of what ends a line.

Git usually handles those well, by defaulting the config value of core.eol to 'native'. However, if a developer does not have that setting for some reason, or committing UNIX-style files from Windows or vice versa, you might get these issues.

It is best to find the source of the issue and deal with it there, otherwise, you can try to set different values for core.eol (lf/crlf), and see if it fixes that. If it only happens on a specific path, and not the whole project, you might be better off defining a gitattributes file for that path.

yhager
  • 1,632
  • 15
  • 16
  • thanks - will try core.eol, but the repository has only been push/pulled between linux machines – EoghanM Sep 08 '11 at 22:47
  • Maybe someone committed a file copied from a Windows machine. – yhager Sep 08 '11 at 22:50
  • On reflection yes, probably the original developers of the codebase (before it was put in git) developed on Windows. – EoghanM Sep 09 '11 at 08:52
  • Setting the core.eol setting any of native, lf or crlf still causes merge conflicts. I'm testing by doing a plain rebase over the last 3 commits (the 'merge conflict' is a 'Could not apply 9c119fc...' message). – EoghanM Sep 09 '11 at 08:57
  • Once things were committed non-natively, you either have to fix it manually, or continue working the old way (unless the code base is inconsistent wrt line endings) – yhager Sep 12 '11 at 23:44