2016-07-28 45 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