这是我的 git 存储库的初始快照
在分支上master
,文件m1
包含
L1
在分支上dev
,文件m1
包含
L1
L2
如果我尝试从 合并dev
,master
则会导致冲突。
$ 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
虽然我没有修改 in 的第 2 行m1
,master
但它是如何导致冲突的呢?
要验证文件的实际内容并确定这是否是由空格引起的:
在分支上master
git branch
dev
* master
$ xxd m1
0000000: 4c31 0a L1.
在分支上dev
$ git checkout dev
Switched to branch 'dev'
$ xxd m1
0000000: 4c31 0a4c 320a L1.L2.
这是我用来创建这个 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