简体   繁体   English

git:在文件末尾通过换行合并冲突

[英]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. 在文件末尾通过换行符之间的差异拉动(合并)git时,经常会遇到冲突。

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'. 通过将core.eol的配置值默认为'native',Git通常可以很好地处理这些问题。 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. 但是,如果开发人员由于某种原因没有该设置,或者从Windows提交UNIX风格的文件(反之亦然),则可能会遇到这些问题。

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. 最好找到问题的根源并在那里解决,否则,您可以尝试为core.eol(lf / crlf)设置不同的值,并查看它是否可以解决。 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. 如果仅在特定路径而不是整个项目上发生,则最好为该路径定义gitattributes文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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