Git子树工作流 - 为什么子树合并/拉总是导致CONFLICT?

时间:2015-12-05 17:21:10

标签: git merge git-subtree

我在一个真实的项目中遇到了这个问题,并设法使用下面的最小步骤重现它。

编辑:这不是一个重复的问题。我看到另一个涉及git subtree add的问题,而这不是这里的情况。

场景是:我有一个大型存储库,我希望将项目的一小部分提供给其他人来处理,并最终在完成后将他们的工作合并回大型仓库。

问题是git subtree merge(以及相关的推/拉)总是导致虚假冲突。

这是完全失败:

root@devbox:/tmp/git-demo# ll
total 164
drwxr-xr-x 2 root root   4096 Dec  5 10:55 ./
drwxrwxrwt 9 root root 159744 Dec  5 10:55 ../

root@devbox:/tmp/git-demo# git init bigrepo
Initialized empty Git repository in /tmp/git-demo/bigrepo/.git/

root@devbox:/tmp/git-demo# cd bigrepo/
root@devbox:/tmp/git-demo/bigrepo# echo 1 > one.txt
root@devbox:/tmp/git-demo/bigrepo# echo 2 > two.txt
root@devbox:/tmp/git-demo/bigrepo# mkdir lib
root@devbox:/tmp/git-demo/bigrepo# echo 3 > lib/three.txt
root@devbox:/tmp/git-demo/bigrepo# echo 4 > lib/four.txt
root@devbox:/tmp/git-demo/bigrepo# git add -A :/
root@devbox:/tmp/git-demo/bigrepo# git commit -minitial
[master (root-commit) 8360303] initial
 4 files changed, 4 insertions(+)
 create mode 100644 lib/four.txt
 create mode 100644 lib/three.txt
 create mode 100644 one.txt
 create mode 100644 two.txt

这是我为合作者准备一个小型仓库的地方:

root@devbox:/tmp/git-demo/bigrepo# git subtree split --prefix=lib
87938ea784d67b83d61e6292a85788f3bdb28fab
root@devbox:/tmp/git-demo/bigrepo# git checkout -b lib_br 87938ea784d67b83d61e6292a85788f3bdb28fab
Switched to a new branch 'lib_br'

root@devbox:/tmp/git-demo/bigrepo# git init ../smallrepo
Initialized empty Git repository in /tmp/git-demo/smallrepo/.git/

root@devbox:/tmp/git-demo/bigrepo# git remote add small ../smallrepo
root@devbox:/tmp/git-demo/bigrepo# git push small lib_br:work
Counting objects: 4, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (4/4), 238 bytes | 0 bytes/s, done.
Total 4 (delta 0), reused 0 (delta 0)
To ../smallrepo
 * [new branch]      lib_br -> work

现在假装你是在另一台机器上工作的合作者。忽略我使用本地存储库的事实,使用github时问题是一样的。准备做一些工作:

root@devbox:/tmp/git-demo/bigrepo# cd ../collaborator/
root@devbox:/tmp/git-demo/collaborator# git clone ../smallrepo
Cloning into 'smallrepo'...
done.
root@devbox:/tmp/git-demo/collaborator# cd smallrepo/
root@devbox:/tmp/git-demo/collaborator/smallrepo# ls
four.txt  three.txt
root@devbox:/tmp/git-demo/collaborator/smallrepo# git status
On branch work
Your branch is up-to-date with 'origin/work'.

nothing to commit, working directory clean

现在努力工作,在文件中添加一行:

root@devbox:/tmp/git-demo/collaborator/smallrepo# echo 3-too >> three.txt
root@devbox:/tmp/git-demo/collaborator/smallrepo# git commit -a -m"added a line"
[work feb5252] added a line
 1 file changed, 1 insertion(+)

Collaborator发布他们的杰作:

root@devbox:/tmp/git-demo/collaborator/smallrepo# git push origin work:work2
Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 265 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To /tmp/git-demo/collaborator/../smallrepo
 * [new branch]      work -> work2

通常协作者会在这里推送到work分支,但我忘了让smallrepo成为一个简单的回购,所以他会推送到work2。与github相比,这并没有改变行为,并且对于你最终会看到的问题应该是无关紧要的。

合作者打包回家。现在再次回到我身边:

root@devbox:/tmp/git-demo/collaborator/smallrepo# cd ../../bigrepo
root@devbox:/tmp/git-demo/bigrepo# git checkout master
Switched to branch 'master'

root@devbox:/tmp/git-demo/bigrepo# ll
total 24
drwxr-xr-x 4 root root 4096 Dec  5 11:06 ./
drwxr-xr-x 5 root root 4096 Dec  5 10:59 ../
drwxr-xr-x 9 root root 4096 Dec  5 11:06 .git/
drwxr-xr-x 2 root root 4096 Dec  5 11:06 lib/
-rw-r--r-- 1 root root    2 Dec  5 11:06 one.txt
-rw-r--r-- 1 root root    2 Dec  5 11:06 two.txt

root@devbox:/tmp/git-demo/bigrepo# git subtree pull --prefix=lib small work2
From ../smallrepo
 * branch            work2      -> FETCH_HEAD
Auto-merging lib/three.txt
CONFLICT (add/add): Merge conflict in lib/three.txt
Automatic merge failed; fix conflicts and then commit the result.

现在有。单线改变不应该是冲突。我在大文件上看到了同样的事情,大变化,小变化,无关紧要。当git subtree merge处理时,任何一方触及的每个文件都会成为冲突。

那么,这是一个错误,还是我做错了什么?

0 个答案:

没有答案