2013-02-11 54 views
3

尝试使用git子树来跨多个项目共享公用库文件。这是我遇到的问题。Git子树推动总是失败

1)添加子树,使我的项目的“lib”子目录来自lib-dk存储库。

$ git subtree add --prefix=lib --squash [email protected]:dwknight/lib-dk.git master 

2)请在 “LIB” 文件的更改

3)更改提交到主要的项目回购

$ git commit -am "update project" 

4)将更新推入主体工程回购

$ git push origin master 

5)将“lib”中的更改推回“lib-dk”回购

$ git subtree push --prefix=lib [email protected]:dwknight/lib-dk.git master 
git push using: [email protected]:dwknight/lib-dk.git master 
To [email protected]:dwknight/lib-dk.git 
! [rejected]  f455c24a79447c6e3fe1690f5709357b7f96828a -> master (non-fast-forward) 
error: failed to push some refs to '[email protected]: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回购中没有任何变化,我也会得到这种拒绝。当我尝试拉动时,它表现得像是有些东西,但我可以通过拉动进行更新。仍然推继续被拒绝。

+1

我没有使用'subtree'命令的经验,但'--squash'操作看起来像一个'rebase'选项。它有什么作用?如果它以某种方式修改分支历史记录,那么可能会导致此问题。 – asm 2013-02-11 16:22:15

回答

2

当我尝试这个没有--squash选项git subtree add,它的工作原理。正如评论者所建议的那样,我认为--squash以无益的方式摆弄着历史。

0

您可能需要使用git add -A .然后git commit而不是git commit -am <message>

因为git-add-A会做:

-A, --all, --no-ignore-removal 
     Update the index not only where the working tree has a file matching <pathspec> but also where the 
     index already has an entry. This adds, modifies, and removes index entries to match the working 
     tree. 

     If no <pathspec> is given when -A option is used, all files in the entire working tree are updated 
     (old versions of Git used to limit the update to the current directory and its subdirectories). 

,另一方面,在git-commit-a会做(没有太多的细节被给出手册页):

-a, --all 
     Tell the command to automatically stage files that have been modified and deleted, but new files 
     you have not told Git about are not affected. 

this可能会对您有所帮助。作者明确呼吁git add -A .