如何将两个单独的不相关的Git存储库合并成一个具有单个历史时间表的存储库 [英] How to combine two separate unrelated Git repositories into one with single history timeline

查看:147
本文介绍了如何将两个单独的不相关的Git存储库合并成一个具有单个历史时间表的存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个不相关的(不共享任何祖先检查)Git仓库,一个是超级仓库,它包含许多较小的项目(让我们称之为仓库A)。另一个只是一个小型项目的临时本地Git仓库(让我们称之为仓库B)。在图形上,它看起来像这样

  A0-B0-C0-D0-E0-F0-G0-HEAD(回购A) 
A0-B0-C0-D0-E0-F0-G0-HEAD(远程/主控裸机回购,并从回购A推)
A1-B1-C1-D1-E1-HEAD(回购B)

理想情况下,我真的想将repo B合并到单个历史时间表的repo A中。因此,看起来我最初是在回购A中开始项目。从图形上看,这将是理想的最终结果。

B1-B0-D1-C0-D0-E0-F0-G0-E1-H(从回购B)-HEAD(新回购A)
A0-A1-B1-B0-D1-C0-D0-E0 -F0-G0-E1-H(从回购B)-HEAD(远程/主裸回购拉动并从回购A推)

我一直在用子模块和子树进行一些阅读(Pro Git是一本相当不错的书),但它们似乎迎合了维护两个独立分支的解决方案,子模块能够从上游拉动变化,子树稍微减少头痛。这两种解决方案都需要额外的专用git命令来处理主和子树/模块分支之间的检入和同步。这两种解决方案都会导致多个时间表(使用--squash时,您甚至会得到3个单独的时间轴)。

与SO最接近的解决方案似乎是谈论移植,但这是真的吗?我们的目标是拥有一个统一的存储库,在这里我可以推送/推入签入,这样就不会有更多的回购B了,最后只会回购A。

解决方案

我想你是这样做的:


  1. git remote add [回购b]

  2. git fetch //将回购b转换为回购a

  3. 保留历史记录:
    A0-A1-B1-B0-D1-C0-D0-E0-F0-G0-E1-H(从回购B)-HEAD(新回购A)
    你可以先选择A0作为开始点,然后再逐一使用git cherry-pick。

希望这对于你。



Tim


I have two unrelated (not sharing any ancestor check in) Git repositories, one is a super repository which consists a number of smaller projects (Lets call it repository A). Another one is just a makeshift local Git repository for a smaller project (lets call it repository B). Graphically, it would look like this

A0-B0-C0-D0-E0-F0-G0-HEAD (repo A)
A0-B0-C0-D0-E0-F0-G0-HEAD (remote/master bare repo pulled & pushed from repo A)
A1-B1-C1-D1-E1-HEAD (repo B)

Ideally, I would really like to merge repo B into repo A with a single history timeline. So it would appear that I originally started project in repo A. Graphically, this would be the ideal end result

A0-A1-B1-B0-D1-C0-D0-E0-F0-G0-E1-H(from repo B)-HEAD (new repo A)
A0-A1-B1-B0-D1-C0-D0-E0-F0-G0-E1-H(from repo B)-HEAD (remote/master bare repo pulled & pushed from repo A)

I have been doing some reading with submodules and subtree (Pro Git is a pretty good book by the way), but both of them seem to cater solution towards maintaining two separate branch with sub module being able to pull changes from upstream and subtree being slightly less headache. Both solution require additional and specialized git commands to handle check ins and sync between master and sub tree/module branch. Both solution also result in multiple timelines (with subtree you even get 3 separate timelines when using --squash).

The closest solution from SO seems to talk about "graft", but is that really it? The goal is to have a single unified repository where I can pull/push check-ins, so that there are no more repo B, just repo A in the end.

解决方案

I think you do it like this:

  1. git remote add [repo b]
  2. git fetch//get the repo b into repo a
  3. due to you want to keep the history like this: A0-A1-B1-B0-D1-C0-D0-E0-F0-G0-E1-H(from repo B)-HEAD (new repo A) you can first select the A0 as a start point, after that, use git cherry-pick one by one.

Hope this is useful for you.

Br, Tim

这篇关于如何将两个单独的不相关的Git存储库合并成一个具有单个历史时间表的存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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