Git合并 - 冲突标记丢失

6

使用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

有什么阻止我审查我的冲突吗?

编辑: 顺便说一下,这个答案没有帮助我。我似乎没有任何 .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

1
如果您运行 git gui 尝试手动合并,您会看到什么? - azurefrog
它指出需要合并冲突,但没有显示文件内容。相反,我看到一条消息说“二进制文件不同”...检查我的测试文件,我发现它以某种原因被编码为UTF-16...如果我使用UTF-8文件重复该过程,我会看看会发生什么。 - abarger
@azurefrog 这是文件编码的问题...一旦我使用了UTF-8,冲突标记就出现了。我感觉自己像个傻瓜。如果Git让我知道它试图比较的是二进制文件就好了!! - abarger
2个回答

9
在我的情况下,冲突标记没有出现,因为冲突文件使用UTF-16编码,这显然与Git不兼容。通过azurefrog建议使用git gui查看文件,我意识到了这一点,它明确指出Git无法比较这些文件,因为它认为它们是二进制文件。
故事的寓意:使用UTF-8编码。

1
你可以(实际上应该)将你的答案标记为正确答案,这样其他人就可以轻松地看到问题的解决方案。 - David Ferenczy Rogožan
有趣的是,我以前从未听说过git在处理UTF-16方面存在问题。这很好知道。 - azurefrog

7
我认为,这可能是由于在您的 .gitconfig 中启用了 rerere 选项所致。它表示“重复使用记录的解决方案”,简单地让 Git 以与先前解决冲突相同的方式解决冲突。 因此,没有冲突标记,因为Git已经解决了该冲突。尝试禁用此选项后重复您的工作流程。

你如何禁用它? - ikmazameti

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接