【发布时间】:2013-01-26 05:13:11
【问题描述】:
尝试使用 git subtree 跨多个项目共享公共库文件。这是我一直遇到的问题。
1) 添加子树,以便我的项目的“lib”子目录来自 lib-dk 存储库。
$ git subtree add --prefix=lib --squash git@bitbucket.org:dwknight/lib-dk.git master
2) 更改“lib”中的文件
3) 向主项目 repo 提交更改
$ git commit -am "update project"
4) 将更新推送到主项目仓库
$ git push origin master
5) 将“lib”中的更改推送回“lib-dk”repo
$ git subtree push --prefix=lib git@bitbucket.org:dwknight/lib-dk.git master
git push using: git@bitbucket.org:dwknight/lib-dk.git master
To git@bitbucket.org:dwknight/lib-dk.git
! [rejected] f455c24a79447c6e3fe1690f5709357b7f96828a -> master (non-fast-forward)
error: failed to push some refs to 'git@bitbucket.org:dwknight/lib-dk.git'
hint: Updates were rejected because the tip of your current branch is behind its remote counterpart. Merge the remote changes (e.g. 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
6) 即使 lib-dk 存储库中没有任何更改,我也会收到此拒绝。当我尝试拉动时,它的行为就像有东西一样,但我可以通过拉动进行更新。推送仍然被拒绝。
【问题讨论】:
-
我没有使用
subtree命令的经验,但--squash操作看起来像rebase选项。它有什么作用?如果它以某种方式修改分支历史记录,则可能会导致此问题。