gpt4 book ai didi

Git + Windows + Visual Studio 分支间行尾问题引起的 merge 冲突

转载 作者:太空狗 更新时间:2023-10-29 13:15:32 25 4
gpt4 key购买 nike

我很难正确地 merge 到分支。分支似乎有行结束问题,因为当我在 Visual Studio 中打开冲突窗口时,它显示多个文件之间有 0 个冲突和 0 个差异。

我在两个分支上都添加了一个 gitattributes 文件,看起来并执行了 repository refresh在两个存储库上。

当我 refreshed两个存储库都没有要提交的更改,即使说明中指出会有要提交的更改(本质上是来自 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

我也检查了我的 global core.autocrlf is equal to true (因为我们所有的开发人员都在 Windows 上使用 Visual Studio)

问题是,当我继续执行上述操作以希望跨两个分支修复和规范化这些线路分支时,我最终遇到了比以前更多的冲突 - 都是由于线路结束:

enter image description here

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

[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
hideDotFiles = dotGitOnly
autocrlf = true
[merge]
renormalize = true

我无计可施,经历了无数 SO 问题/答案 - 谷歌搜索,无济于事 - 我的冲突数量继续上升。

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

更新 1:我已经从 Visual Studio 中复制了所说的“冲突”两个文件,每个文件都进入了自己的 Notepad++ 窗口,并打开了“显示符号 -> 显示行尾” - 然后我比较了两个“冲突”文件,正如你在那里看到的行尾没有区别(两个文件都包含完全相同的 CR/LF,如下图所示)——所以我猜 VS 正在进行 EOL 转换或其他操作?或者,当我将它复制到 Notepad++ 时,它会进行某种 EOL 转换吗?不确定这是否有帮助。

enter image description here

我正在运行 Visual Studio 2015 Update 3

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

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

这是 master( merge 到 master 注意:这个文件在 merge 之前是 CRLF, merge 时 CRLF 必须被转换为 LF): enter image description here

这是我要 merge 的内容: enter image description here

最佳答案

为了更加一致并能够通过扩展名为不同的文件指定行结束符,您可以使用 .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

关于Git + Windows + Visual Studio 分支间行尾问题引起的 merge 冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42347617/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com