Git + Windows + Visual Studio合并由分支之间的行结束问题引起的冲突

998*_*823 6 git github visual-studio git-merge-conflict

我正在努力正确地合并到分支机构.分支似乎有行结束问题,因为当我打开Visual Studio中的冲突窗口时,它显示0个冲突和0个不同文件之间的差异.

我在两个分支上添加了一个gitattributes文件,它在两个存储库中查找并执行了存储库刷新.

当我刷新两个存储库时,没有提交更改,即使指令指出将提交更改(实际上更改来自EOL转换).

这是我的gitattributes

# Auto detect text files and perform LF normalization
* text=auto

# Custom for Visual Studio
*.cs     diff=csharp

# Standard to msysgit
*.doc    diff=astextplain
*.DOC    diff=astextplain
*.docx   diff=astextplain
*.DOCX   diff=astextplain
*.dot    diff=astextplain
*.DOT    diff=astextplain
*.pdf    diff=astextplain
*.PDF    diff=astextplain
*.rtf    diff=astextplain
*.RTF    diff=astextplain
Run Code Online (Sandbox Code Playgroud)

我也检查过,我的全局core.autocrlf等于true(因为我们所有的开发人员都在Windows上使用Visual Studio)

问题是,当我继续做以上操作以期在两个分支中修复和规范化这些分支时,我最终会遇到比以前更多的冲突 - 所有这些都是由于行结束:

在此输入图像描述

.git/config文件(不包括分支引用)

[core]
    repositoryformatversion = 0
    filemode = false
    bare = false
    logallrefupdates = true
    symlinks = false
    ignorecase = true
    hideDotFiles = dotGitOnly
    autocrlf = true
[merge]
    renormalize = true
Run Code Online (Sandbox Code Playgroud)

我在我的智慧结束,经历无数的SO问题/答案 - 谷歌搜索,无济于事 - 我的冲突计数继续上升.

另请注意:我在TFS上使用GIT - 不确定这是否会改变.

更新1: 我已经从Visual Studio中复制了所说的"冲突"两个文件,每个文件都进入了自己的Notepad ++窗口,其中"show symbols - > show end of line"打开 - 然后我比较了两个"冲突"文件和你一样可以看到行结尾没有区别(两个文件都包含完全相同的CR/LF,如下图所示) - 所以我猜测VS正在进行EOL转换或其他什么?或者,当我将它复制到Notepad ++中时,它会进行某种EOL转换?不确定这是否有帮助.

在此输入图像描述

我正在运行Visual Studio 2015 Update 3

更新2: 我添加了这个方便的End of Line Visual Studio扩展,显示了EOL字符文件,因此我可以在合并/差异屏幕中看到所有EOL字符,看起来它们在文件之间完全匹配.

更新3: 好的 - 所以我想我可能会在这里做点什么...我做了一个合并,然后打开一个冲突的文件,这就是我发现...我正在合并的分支是使用CRLF,分支我正在合并INTO正在使用LF - 所以它看起来确实和EOL问题.我不确定如何批量修复此问题?我虽然我的初始存储库刷新我上面列出会做到这一点,显然不是.

这是master(合并到master中注意:这个文件在合并之前是CRLF,在合并CRLF时必须转换为LF): 在此输入图像描述

以下是我要合并的内容: 在此输入图像描述

小智 3

为了更加一致并能够通过扩展名指定不同文件的行结尾,您可以使用 .gitattributes 文件。该文件已提交到存储库并将覆盖开发人员设置。.gitattributes 文件应在存储库的根目录中创建,并像任何其他文件一样提交到存储库中。

# Set behaviour for all files, in case developers don't have core.autocrlf set.
* text=auto

# Explicitly declare text files we want to always be normalized and converted to native line endings on checkout.
*.txt text

# Declare files that will always have CRLF line endings on checkout.
*.sln text eol=crlf

# Denote all files that are truly binary and should not be modified.
*.zip binary
Run Code Online (Sandbox Code Playgroud)