将子目录放入独立的存储库,然后再合并回主存储库 [英] Sub-directory into independent repository and later merge back into main repository

查看:126
本文介绍了将子目录放入独立的存储库,然后再合并回主存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我所做的尝试是将一个子树:

 %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书中阅读Subtree Merging: https://git-scm.com/book/en/v1/Git-Tools-Subtree-Merging 并试过:

 %git读取树--prefix = project_a / directory_a -u directory_a_branch 
错误:条目'project_a / directory_a / README'与'project_a / directory_a / README重叠。无法绑定。

类似的问题在这里讨论: git:将一个分支的子树合并到另一个分支,但对我来说缺乏足够的答案。

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

我的意图是一个存储库就像是另一个存储库的子存储库,并且将工作重新合并到主存储库将尽可能简单,因为这两个存储库共享相同的文件。



是否可以使用Git解决这个任务而不会有丑陋的黑客?

解决方案

  git merge -s subtree directory_a_branch master 


I want to create independent repository out of a sub-directory of an existing git repository and later be capable to merge it back to main repository. Basically I want to separate one sub-directory of a monolithic git repository for specific work and be able to merge commits back into monolithic repo.

What I did try was split a subtree:

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

Then I could clone directory_a_branch into separate repository and start working on it:

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

Later I could push changes back to main repository (under directory_a_branch) -- everything is normal and by the book right now.

Problems start with my strategy in merging directory_a_branch, which fail since I clearly fail to fully understand what I'm doing.

I read "Subtree Merging" from Pro Git book: https://git-scm.com/book/en/v1/Git-Tools-Subtree-Merging and tried:

% 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.

Similar issue is discussed here: git: merging a subtree from one branch to another, but lacks sufficient answer for me.

Creating subtree branch is not my intention and this problem may be solved other ways. Maybe with submodules?

My intention is that one repository is like sub-repository to another and merging work back to main repository would be as easy as possible, since both repositories share the same files.

Is it possible to solve this task with Git without ugly hacks?

解决方案

One-liner which solves this:

 git merge -s subtree directory_a_branch master

这篇关于将子目录放入独立的存储库,然后再合并回主存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆