2017-07-27 28 views
2

我知道這是不尋常的,但我的git repo之一,作爲一個收集所有回購,變得太大,我想分成兩個,分別爲repoArepoBGit拆分和清除

我發現做分裂的「Forking a sub directory of a repository on GitHub and making it part of my own repo」的一種方式,但是,只講述分裂,我想歷史上被分割爲好,這樣repoA將只包含的repoA歷史,而不是repoB和反之亦然。否則,我會得到兩個回購券,但因爲它保存的所有歷史記錄而使其規模增加一倍。

UPDATE:

由於@ElpieKay指出來看看git filter-branch(而不是git clean,我發現與 「混帳清除」 搜索時),我發現這一點:

https://help.github.com/articles/splitting-a-subfolder-out-into-a-new-repository/

這正是我正在尋找的。但是,還有一個問題 - 如何從repoB中刪除repoA內容?即,分裂出repoA的時候,我只需要做好,

git filter-branch --prune-empty --subdirectory-filter sub1/sub2/sub3 master 

所以在repoB,如何刪除sub1/sub2/sub3,同時保持一切

此外,在上述文檔此命令,

git remote set-url origin https://github.com/USERNAME/NEW-REPOSITORY-NAME.git 

當我試了一下,只更新了fetch URL和push一個仍然指向舊的。我錯過了什麼?

+0

'git的過濾branch'兩次。一個從歷史中刪除repoA,另一個刪除repoB。將創建兩個重寫的歷史記錄。 – ElpieKay

+0

謝謝@ElpieKay,OP問題縮小了。 – xpt

回答

1

那麼在repoB,如何刪除sub1/sub2/sub3,同時保持一切?

你做一個指數過濾器:

cd repoB 
git filter-branch --prune-empty --index-filter \ 
    'git rm -r -f -q --ignore-unmatch --cached sub1/sub2/sub3' --tag-name-filter cat -- --all 

將從repoA刪除sub1/sub2/sub3

您將需要一個git push --force更新您的上游回購(從repoA刪除這些文件夾)

+0

謝謝@馮。我試過了,然後用'git log --stat'來檢查一下。但是,其中仍有日誌條目與'sub1/sub2/sub3'的更改有關,但日誌輸出中未列出相關文件。我們可以添加更多選項來徹底刪除與'sub1/sub2/sub3'關聯的所有git日誌嗎?謝謝。 – xpt

+0

@xpt你可以嘗試相同的命令,但是使用'--prune-empty',即'git filter-branch --prune-empty ...' – VonC

+0

是的! '--prune-empty'就是訣竅!請更新答案,然後我會接受。 – xpt