【问题标题】:Sub-directory into independent repository and later merge back into main repository子目录到独立存储库,然后合并回主存储库
【发布时间】:2015-06-08 08:27:23
【问题描述】:

我想从现有 git 存储库的子目录中创建独立的存储库,然后能够将其合并回主存储库。基本上我想为特定的工作分离一个单一的 git 存储库的一个子目录,并能够将提交合并回单一的 repo。

我尝试的是拆分子树:

% git subtree split -P project_a/directory_a -b directory_a_branch

然后我可以将directory_a_branch 克隆到单独的存储库中并开始处理它:

% git clone -b directory_a_branch --single-branch file:///path/to/main_repo

稍后我可以将更改推送回主存储库(在 directory_a_branch 下)——一切正常,现在按规定。

问题从我合并directory_a_branch 的策略开始,因为我显然无法完全理解我在做什么,所以失败了。

我从 Pro Git 书中阅读了“子树合并”:https://git-scm.com/book/en/v1/Git-Tools-Subtree-Merging 并尝试:

% git read-tree --prefix=project_a/directory_a -u directory_a_branch
error: Entry 'project_a/directory_a/README' overlaps with 'project_a/directory_a/README'.  Cannot bind.

这里讨论了类似的问题:git: merging a subtree from one branch to another,但对我来说缺乏足够的答案。

创建子树分支不是我的意图,这个问题可以通过其他方式解决。也许有子模块?

我的意图是一个存储库就像另一个存储库的子存储库,并且将工作合并回主存储库将尽可能容易,因为两个存储库共享相同的文件。

有没有可能用 Git 解决这个任务而没有丑陋的 hack?

【问题讨论】:

    标签: git merge subtree


    【解决方案1】:

    本文描述了解决此问题的一种方法(可能会满足特定用例):https://lostechies.com/johnteague/2014/04/04/using-git-subtrees-to-split-a-repository/

    基本上你从master(&提交)中删除project_a/directory_a,然后从(远程)分支中删除subtree add --prefix,如下所示:

    git subtree add --prefix=project_a/directory_a remote branch
    

    但这不是 100%,因为有更好的方法来解决这个问题。

    【讨论】:

      【解决方案2】:

      解决这个问题的单线:

       git merge -s subtree directory_a_branch master
      

      【讨论】:

        猜你喜欢
        • 2015-06-28
        • 2011-09-19
        • 2011-12-09
        • 2011-11-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-09-26
        • 2013-12-18
        相关资源
        最近更新 更多