我有一个更大的 git 存储库 (A),它与我的另一个项目 (B) 共享一定数量的代码。为了使维护更容易,我决定使用公共代码 (C) 创建第三个存储库,然后通过git subtree
.
我准备好 A 中的所有内容(将公共代码放在文件夹“sub”中)并使用Detach (move) subdirectory 中描述的过程到单独的 Git 存储库中创建 C
现在我只有几个提交的 C,我想把它放回 A,文件夹 sub。我使用了http://www.kernel.org/pub/software/scm/git/docs/howto/using-merge-subtree.html中描述的方法,因为子文件夹的所有提交现在都被复制了。我不太介意这一点,但是现在我不知道如何继续使用这个子目录。
我在要推送到 C 的 A/sub 中进行了其他更改。如git subtree push changes back to subtree project中所述,我使用了
git subtree split --prefix sub -b split-branch
只用子树创建一个分支。这需要一些时间,但成功完成。正在做
git checkout split-branch
git push remote-c master
给我
failed to push some refs to "remote-c"
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and merge the remote changes
hint: (e.g. 'git pull') before pushing again.
但是 agit pull remote-c master
说我已经是最新的了。
我该如何解决这种情况?
EDIT1:我试图用一个小测试脚本重现这个问题。执行此脚本:
( cd testC; git init --bare )
( cd testA; git init )
cd testA
git remote add C ../testC
mkdir sub
echo subFile1 > sub/subFile1
echo subFile2 > sub/subFile2
git add sub
git commit -m "adding files"
echo FileA > fileA
echo FileB > fileB
git add fileA fileB
git commit -m "add root level files"
# extract subtree and push to C
git subtree split -P sub -b split-branch
git push C split-branch:master
# try to make an update in C
git checkout -b cmaster C/master
echo subFile2new > subFile2
git commit subFile2 -m "updated #2 in C"
git push
这导致
To ../testC
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to '../testC'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. If you did not intend to push that branch, you may want to
hint: specify branches to push or set the 'push.default' configuration
hint: variable to 'current' or 'upstream' to push only the current branch.