2016-02-22 27 views
0

我有一個我的團隊一直在研究的git存儲庫。我們稱之爲main回購。現在我需要外部完成的一些事情,所以我拷貝了存儲庫中的文件,並創建了一個新文件(我們稱之爲snapshot回購)。使用快照作爲上游

現在這兩個存儲庫都包含一些更改,我希望git瞭解snapshot存儲庫的起點是main回購的特定提交,然後合併來自兩個回購的更改。或者從snapshot挑選櫻桃,然後不時推出新的快照。

你會怎麼做呢?或者正在製作副本已經是一個錯誤?

+0

試圖在回購之間進行同步,就好像它們在同一個回購庫內的分支一樣,對我來說就像是破解。使用單個存儲庫有什麼問題嗎? –

+0

好吧,主要是我把公共嗜好項目的長期git歷史記錄做得很不舒服。 – vertti

+0

你可以創建一個新的分支,然後擠壓一些提交?應該謹慎使用櫻桃採摘,IMO,特別是如果你打算在某個時候合併全部源分支。 –

回答

0

或者正在複印已經是一個錯誤?

是的。你應該做了一個淺層克隆(有1次提交的歷史記錄,但完全用提交快照的地方完成),你將能夠共享提交,因爲2存儲庫至少有一個提交共同。

你仍然可以嘗試使用「git的變基--onto」如果歷史「的外部材料」沒有,不包含合併做某事

還是有點困難,但更好的長在存儲庫中執行淺層克隆,將其獲取到現有的存儲庫並執行'git replace'以更改新的root提交!

0

裏面的git的工具箱中,有一個隱藏的命令,它應該與你的情況幫:
git replace

這裏是一個文章,解釋瞭如何使用它:
Replace Kicker

這裏有一種方法使用方法:

# start with a clone of your main repo : 
git clone myrepo grafting 
cd grafting 

# add a copy of the 'external' repo as a remote : 
git remote add external /path/to/external 
git fetch external 

# your main repo will be referenced as 'origin', the external repo as 'external' 

# * you will need the hash of the original commit from which you created the 
# inital 'external' commit : I will call this commit <base> 

# * you need the hash of the first commit on external : 
# I will call this commit <external> 
git log --oneline external/master | tail -1 

# "replace" the initial commit on external with the commit of your main repo : 
git replace <external> <base> 

您現在應該能夠使用最Git的命令,彷彿external嫁接在origin內。


我的建議是:從這個grafting目錄,建立一個乾淨的新的回購協議,您將作爲然後爲你和外部團隊的參考使用。