2014-09-23 57 views
2

我想從具有完整歷史記錄的子目錄中將遠程存儲庫合併和分離。有幾種方法和問題如何做到這一點。
我第一次嘗試使用子樹但它似乎不重寫文件的歷史,所以我不能查看合併存儲庫的歷史。將遠程存儲庫導入爲具有完整歷史記錄的子目錄

下一個嘗試是對手冊中顯示了合併它像賽斯·羅伯遜他answer

,唯一的辦法,以使這項工作:強制的Git通過創建一個子目錄和移動內容到識別重命名 它。

mkdir bdir 
git mv B bdir 
git commit -a -m bdir-rename 

返回到庫 「A」 和取回併合並 「B」 的內容:

cd ../a 
git remote add -f B ../b 
git merge -s ours --no-commit B/master 
git read-tree --prefix= -u B/master 
git commit -m "subtree merge B into bdir" 

表明他們現在已經合併:

cd bdir 
echo BBB>>B 
git commit -a -m BBB 

爲了證明完整的歷史保存在連接鏈中:

git log --follow B 

到目前爲止工作正常,但似乎大多數工具不使用後跟選項爲git log

所以我需要另一種方法來做到這一點。任何人都可以告訴我一種不重命名並保持歷史的方式嗎?

在此先感謝。

+0

從連接的同回答一下過濾器分支選項。 – 2014-09-23 14:24:25

+0

@AndrewC Uhm ...鏈接的答案不包含任何關於過濾器分支選項的內容。我無法追隨你的意思。 – CSchulz 2014-09-23 14:37:39

+0

您是否看到http://git-scm.com/book/en/Git-Tools-Subtree-Merging? – 2014-09-23 15:23:26

回答

2

最後的解決方案是「簡單的」導入回購作爲回購的子目錄。我偶然發現了一個small tool,其中包含了如何使用git filter-branch的說明。

git filter-branch --index-filter \ 
    'git ls-files -s | sed "s-\t\"*-&newsubdir/-" | GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info && mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' \ 
    --tag-name-filter cat \ 
    -- --all 

完整的方法是在回購使用上面貼git filter-branch,之後在回購運行以下命令的導入的東西:

git remote add -f B ../b 
git merge -s ours --no-commit B/master 
git read-tree --prefix= -u B/master 
git commit -m "subtree merge B into bdir" 
相關問題