2016-07-28 44 views
0

我想將git存儲庫分成兩部分, 「項目」和「項目/工具」。目前有兩個分支(「主」項目,「工具」項目/工具)反映這一發展(在這兩個具體的變化):將git子項目從兩個分支中分離出來

repo(s)  branch(es) 
    ------------- ------------- 
now project  master, tools 
         |  | 
new project  master  | 
    tools   master <--+ 

我能不能刪除/在各自的移動相應的文件分支(例如刪除「master」分支中的「tools」dir以及除「tools」分支中的「tools」之外的所有東西),然後以某種方式從這兩個分支創建獨立的存儲庫(複製,刪除其他分支,重命名分支和存儲庫)?

是否有直接自動執行此操作的命令(git-subtree split或git filter-branch)?

或者我應該先合併分支,然後按照上述任一鏈接(1,2)中的描述進行操作。

+0

在您擔心,一個簡單的方法來做到這一點可能只是創建你原來的回購,每個分支的兩個克隆的文件,同時,我合併了分支,將「項目」克隆到「工具」,並使用[2]中描述的過濾分支方法來提取「工具」。在「項目」中,我剛剛刪除了子目錄「工具」。 – handle

回答

1

如果每個分支的只有感動使用git clone --single-branch --branch [master/tools]

--[no-]single-branch 
     Clone only the history leading to the tip of a single branch, either specified by the --branch option or the primary 
     branch remote's HEAD points at. When creating a shallow clone with the --depth option, this is the default, unless 
     --no-single-branch is given to fetch the histories near the tips of all branches. Further fetches into the resulting 
     repository will only update the remote-tracking branch for the branch this option was used for the initial cloning. If 
     the HEAD at the remote did not point at any branch when --single-branch clone was made, no remote-tracking branch is 
     created. 
+0

感謝你們,但是我最近才從「主人」那裏分支出「工具」,所以我認爲他們的歷史幾乎是一樣的。但是這帶來了其他問題,因爲現在我真的不需要所有的歷史。我會很快嘗試這個。文檔:https://git-scm.com/docs/git-clone#_options – handle

+0

您可以從上面的步驟開始,然後進行過濾分支操作,以刪除您不想在每個分支中使用的垃圾,儘管重寫歷史記錄(如果這是關注的話)。 – DavidN