如何在不更改历史提交哈希的情况下将一个git repo拆分为两个

时间:2015-03-19 04:06:48

标签: git

我有一个像GIT一样的回购:

                     / --- [lots of work] 
                    /   
 root --- ref_a --- .---- [ Lots of work ]

        orphane commit 
              based on ref_a--- [Lots ofworks]
                            \ --- [lots of work] 

我想把这个回购拆分成两个回购,比如

repo1:

                     / --- [lots of work] 
                    /   
 root --- ref_a --- .---- [ Lots of work ]

repo2:

        orphane commit 
              based on ref_a--- [Lots ofworks]
                            \ --- [lots of work] 

我希望保持所有提交哈希完整。

有可能吗?

1 个答案:

答案 0 :(得分:1)

                 / --- [lots of work] (branch1)
                /   
 root --- ref_a --- .---- [ Lots of work ] (branch2)

      orphane commit 
            based on ref_a--- [Lots ofworks] (branch3)
                          \ --- [lots of work] (branch4)
  1. 将整个存储库复制到一个新文件夹中(例如,你的仓库在〜/ myrepo中,新的仓库将在〜/ newrepo中)
  2. 在〜/ myrepo中删除分支branch3和branch4;在〜/ newrepo中删除分支branch1和branch2。
  3. 如果您有远程存储库,您正在从原始存储库推送,请不要忘记删除或更新〜/ newrepo的远程存储库。
  4. 完成。稍后,Git GC将删除未引用的提交,现有提交的哈希值当然会保持不变。