【问题标题】:Git merge - Conflict markers missingGit合并 - 缺少冲突标记
【发布时间】:2015-09-17 23:02:07
【问题描述】:

使用 Windows 7,git 1.9.5.msysgit.1

我读过的关于 Git 中合并冲突的教程表明,失败的合并会导致冲突标记被放置在文件中的问题点。我似乎无法让这件事发生。以下是新存储库的示例工作流程:

git init
notepad file1.txt    #make some edits
git add .
git commit -m "msg"

git branch mybranch
git checkout mybranch
notepad file1.txt #make some edits on line 3
git add .
git commit -m "msg"

git checkout master
notepad file1.txt #make a conflicting edit on line 3
git add .
git commit -m "msg"
git merge mybranch
#error: 'merge' is not possible because you have unmerged files

notepad file1.txt

上次打开 file1.txt 后,我​​期待在第 3 行看到标志 >>>>>>>> 和 ========== 冲突标记...但是那里什么也没有,只是出现在主分支中的文件文本。我的全局 .gitconfig 文件:

[user]
    name = Andrew Barger
[core]
[core]
    attributesfile = ~/.gitattribtues
    editor = 'C:\\Program Files (x86)\\Vim\\VIM74\\gvim.exe'
[merge]
    conflictStyle = diff3
[rerere]
    enabled = true

是什么阻止我查看我的冲突?

编辑: This answer,顺便说一句,没有帮助我。我似乎没有任何 .gitattributes 文件。不过,这里是gitconfig --list 的输出,如果有帮助的话:

PS C:\GitRepos\git_sandbox> git config --list
core.symlinks=false
core.autocrlf=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
pack.packsizelimit=2g
help.format=html
http.sslcainfo=/bin/curl-ca-bundle.crt
sendemail.smtpserver=/bin/msmtp.exe
diff.astextplain.textconv=astextplain
rebase.autosquash=true
user.name=Andrew Barger
core.attributesfile=~/.gitattribtues
core.editor='C:\Program Files (x86)\Vim\VIM74\gvim.exe'
merge.conflictstyle=diff3
rerere.enabled=true
alias.edit-unmerged=!f() { git diff --name-status --diff-filter=U | cut -f2 ; }; vim `f`
alias.add-unmerged=!f() { git diff --name-status --diff-filter=U | cut -f2 ; }; git add `f`
core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.symlinks=false
core.ignorecase=true
core.hidedotfiles=dotGitOnly

【问题讨论】:

  • 如果您运行git gui 尝试手动合并,您会看到什么?
  • 它指出它需要合并冲突,但没有显示文件内容。相反,我看到一条消息说“二进制文件不同”...检查我的测试文件,我发现它出于某种原因以 UTF-16 编码...我会看看如果我使用 UTF- 重复该过程会发生什么- 8个文件。
  • @azurefrog 它是文件编码...一旦我使用 UTF-8,就会出现冲突标记。我觉得自己像个假人。如果只有 Git 让我知道它正在尝试比较它认为是二进制的东西!

标签: git-merge merge-conflict-resolution


【解决方案1】:

在我的例子中,冲突标记没有出现,因为冲突文件是使用 UTF-16 编码的,这显然不能很好地与 Git 配合使用。我意识到这一点是因为 azurefrog 建议使用 git gui 查看文件,这清楚地表明 Git 无法比较文件,因为它认为它们是二进制文件。

故事的寓意:使用 UTF-8 编码。

【讨论】:

  • 您可以(实际上应该)将您的答案标记为答案,以便其他人可以轻松查看您的问题的解决方案。
  • 有趣,我以前从未听说过 git 处理 UTF-16 的问题。很高兴知道这一点。
【解决方案2】:

我想说,这可能是由您的.gitconfig 中启用的rerere 选项引起的。它的意思是“重复使用记录的解决方案”并且只是说 Git 以与之前解决冲突相同的方式解决冲突

因此没有冲突标记,因为 Git 实际上已经解决了该冲突。尝试在禁用此选项的情况下重复您的工作流程。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-24
    • 1970-01-01
    • 1970-01-01
    • 2012-08-25
    • 2012-07-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多