将git子项目从两个分支

时间:2016-07-28 14:34:21

标签: git

我想将一个git存储库分成两个,例如"项目"和"项目/工具"。目前有两个分支("主要"用于项目,"工具和#34;用于项目/工具)反映了这一发展(两者的具体变化):

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

我可以删除/移动各自分支机构中的相应文件(例如删除&#34;工具&#34; dir in&#34; master&#34;分支和除#34;工具&#34;之外的所有内容&#34; tools&#34; branch)然后以某种方式从这两个分支创建独立的存储库(复制,删除其他分支,重命名分支和存储库)?

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

或者我应该首先合并分支,然后按照上面任一链接(12)中的说明进行操作。

1 个答案:

答案 0 :(得分: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.