简体   繁体   中英

git: merge conflicts over newline at end of file

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM