为什么会导致合并冲突? [英] Why is it resulting in a merge conflict?

查看:335
本文介绍了为什么会导致合并冲突?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的git仓库的初始快照





分支 master ,文件 m1 包含

  L1 

在分支 dev ,档案 m1 包含

  L1 
L2

如果我尝试合并 dev from master ,这会导致冲突。

  $ git checkout master 
转换到分支'master'

$ git merge dev dev
自动合并m1
CONFLICT(内容):在m1中合并冲突
自动合并合并失败;修复冲突,然后提交结果。

$ git diff
diff --cc m1
index 078f94b,9f46047..0000000
--- a / m1
+++ b / m1
@@@ -1,1 -1,2 +1,5 @@@
L1
++ << {< HEAD
++ =======
+ L2
++>>>>>>> dev

虽然我没有修改 m1 $ master ,它是如何导致冲突的?



验证文件的实际内容和以确保这是否由空白引起:



在分支 master

  git branch 
dev
* master

$ xxd m1
0000000:4c31 0a L1 。

分支 dev

  $ git checkout dev 
转换到分支'dev'

$ xxd m1
0000000: 4c31 0a4c 320a L1.L2。

以下是我用来创建此回购的脚本。

 #!/ bin / bash 

mkdir git_demo
cd git_demo
git init

touch m1
git add。
git commit -m添加文件:m1
#需要sleep,否则会创建一个不同的repo,可能是因为* some *文件系统问题!
sleep 1

git branch dev
echo L1>> m1
git add。
git commit -m添加行L1到m1
#需要sleep,否则会创建一个不同的repo,可能是因为* some *文件系统问题!
sleep 1

git checkout dev
echo L1>> m1
git add。
git commit -m添加行L1到m1
#需要sleep,否则会创建一个不同的repo,可能是因为* some *文件系统问题!
sleep 1

echo L2>> m1
git add。
git commit -m将第二行添加到m1
#sleep需要,否则会创建一个不同的回购站,可能是因为* some *文件系统问题!

gitg --all
git checkout master
git merge dev


解决方案

答案是存在冲突,因为没有任何



你可以在这里看到他们没有共享同一棵树



[]






This was the initial snapshot of my git repository

On branch master, file m1 contains

L1

On branch dev, file m1 contains

L1
L2

If I try to merge dev from master, it results in a conflict.

$ git checkout master
Switched to branch 'master'

$ git merge dev
Auto-merging m1
CONFLICT (content): Merge conflict in m1
Automatic merge failed; fix conflicts and then commit the result.

$ git diff
diff --cc m1
index 078f94b,9f46047..0000000
--- a/m1
+++ b/m1
@@@ -1,1 -1,2 +1,5 @@@
  L1
++<<<<<<< HEAD
++=======
+ L2
++>>>>>>> dev

Though I didn't modify line 2 of m1 in master, how did it result in a conflict?

To verify actual contents of the file and to be sure if this is caused by white-spaces:

On branch master

git branch
  dev
* master

$ xxd m1
0000000: 4c31 0a                                  L1.

On branch dev

$ git checkout dev
Switched to branch 'dev'

$ xxd m1
0000000: 4c31 0a4c 320a                           L1.L2.

Here's the script I used to create this repo.

#!/bin/bash

mkdir git_demo
cd git_demo
git init

touch m1
git add .
git commit -m "Added file: m1"
# sleep is needed, otherwise a different repo is being created, probably because of *some* filesystem issue!
sleep 1

git branch dev
echo L1 >> m1
git add .
git commit -m "Added line L1 to m1"
# sleep is needed, otherwise a different repo is being created, probably because of *some* filesystem issue!
sleep 1

git checkout dev
echo L1 >> m1
git add .
git commit -m "Added line L1 to m1"
# sleep is needed, otherwise a different repo is being created, probably because of *some* filesystem issue!
sleep 1

echo L2 >> m1
git add .
git commit -m "Added line L2 to m1"
# sleep is needed, otherwise a different repo is being created, probably because of *some* filesystem issue!

gitg --all
git checkout master
git merge dev

解决方案

The answer is that there is a conflict because there isn't any merge-base commit for the 2 branches.

Here is how to generate the problem in fewer steps.
Create orphan branch (Orphan branch is branch without any history)

You can see here that they are not sharing the same tree

[]

这篇关于为什么会导致合并冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆