我创建了新分支并在一个文件中添加了几行。之后我想将它 merge 到 master 但 git 显示冲突:
<<<<<<< destination:ad27cc8d6bb445757c38541eb57ea7d3cba944b3
=======
foo
bar
>>>>>>> source:385f662b3668c9173dd757e850ceba54cfd05560
如果我只添加几行,我不明白为什么会发生冲突。那么,有什么问题吗?
已解决:
我交换了几行的位置,Bitbucket 没有显示冲突。在 Git Bash 中 merge 后,我看到并解决了这个问题。
最佳答案
我可以按如下方式重现您的冲突:
$ git init
$ echo a >test
$ git add test
$ git commit -m msg
[master (root-commit) eac86cc] msg
1 file changed, 1 insertion(+)
create mode 100644 test
$ git checkout -b source
Switched to a new branch 'source'
$ printf 'foo\nbar\n' >test
$ git commit -am source
[source 9f22aa2] source
1 file changed, 2 insertions(+), 1 deletion(-)
$ git checkout master
Switched to branch 'master'
$ >test
$ git commit -am destination
[master 45e3e19] destination
1 file changed, 1 deletion(-)
$ git -c merge.conflictstyle=merge merge source
Auto-merging test
CONFLICT (content): Merge conflict in test
Automatic merge failed; fix conflicts and then commit the result.
$ cat test
<<<<<<< HEAD
=======
foo
bar
>>>>>>> source
发生的事情是一个分支将 a
更改为 foo
/bar
而另一个分支删除了 a
。不可能从简单的 merge 样式冲突标记中分辨出来,但如果您使用 merge.conflictstyle=diff3
,那么您会看到类似于下面的输出,这使得存在冲突的原因显而易见。
显然,您的冲突在细节上很可能有所不同。
<<<<<<< HEAD
||||||| merged common ancestors
a
=======
foo
bar
>>>>>>> source
关于Git:什么都没有的奇怪冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25280164/