2011-08-19 37 views
1

我有兩個git回購站,我在本地機器上克隆。我試圖從申請一個回購到其他的變化:在git中的另一個本地回購庫中引用一個本地回購站中的sha1

cd path/to/local-repo1 
git fetch path/to/local-repo2 <sha1> 
// cherry-pick from fetch head, etc. 

我越來越:

fatal: Couldn't find remote ref <sha1> 
fatal: The remote end hung up unexpectedly 

我發現git: Apply changes introduced by commit in one repo to another repo,但它爲什麼是混帳不承認的SHA1另一個本地回購?原來,如果我用一個分支的名稱替換sha1,它會成功,但我需要使用大量的sha1來做到這一點,並且不想爲每個分支創建一個分支來引用它們。

+2

這不是你的具體問題的答案,但你不*有*創建分支和獲取每一個。你可以只添加'local-repo2'作爲遠程和'git fetch local-repo2',然後挑選哈希。 –

回答

1

git fetch,你試圖使用的形式是:

git fetch <repository> <refspec> 

但是,你SHA1SUM是(不可能!)一個有效的Refspec。 refspec定義源和目標存儲庫之間的refs(通常是分支名稱)之間的映射。 SHA1sums(對象名稱)與refs不同,並且錯誤告訴您,當您執行git fetch path/to/local-repo2 f414f31時,它將refspec擴展爲f414f31:f414f31,然後在遠程存儲庫中找不到參考​​。那是因爲它不是參考。

因此,假設您的承諾是在當地的分支機構的遠程倉庫,我將做到以下幾點:

git remote add other-local path/to/local-repo2 
git fetch other-local 
git cherry-pick f414f31 

形式git fetch <remote-name>取下遠程儲存於遠程跟蹤分行的所有地方分公司refs/remotes/<remote-name>,並確保這些分支(包括歷史記錄中的所有提交)所需的所有對象都存在於本地存儲庫中。