2013-05-30 99 views
15

我試圖用git subtree add向我的項目添加一個回購(稱爲牛)。特別是,我想添加分支stable(這不是master分支)。我想:從分支添加git子樹

git subtree add -P cow https://github.com/geoffryan/cow.git stable 

但這返回的錯誤

'stable' does not refer to a commit. 

我也試過:

git subtree add -P cow https://github.com/geoffryan/cow.git cow/stable 
'cow/stable' does not refer to a commit. 

和:

git subtree add -P cow https://github.com/geoffryan/cow.git ca26d248a12c21264e32a2c212381cafb578c9fb 
'ca26d248a12c21264e32a2c212381cafb578c9fb' does not refer to a commit. 

哈希是最新提交在stable分支中。我在網上看到的使用示例全部使用master進行提交,是否可以在非主分支上使用subtree add

回答

24

這似乎是工作

$ git remote add cow https://github.com/geoffryan/cow.git 
$ git fetch cow 
$ git subtree add -P cow cow/stable 
Added dir 'cow' 

我不知道如何使用直接命令與存儲庫的一部分。

+1

這樣做!謝謝:) –

+0

但是,污染父母回購與一堆不必要的承諾從牛回購... -/ –

+0

哪些是不需要的承諾? – gipi

0

我遇到類似的問題。但是,gipi的解決方案對我無效。奇怪的是,當我添加主分支everythins是好的,但是當我想添加其他分支,它返回

fatal: Couldn't find remote ref xxx/yyy 
Unexpected end of command stream 

所以,我想另一種方式:

mkdir tmp 
cd tmp 
git init 
git clone url_for_xxx.git yyy 
從臨時代表的主分支

而且subtree add

git subtree add -P yyy /path/to/tmp/ master