2013-02-11 107 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 .