如何组合两个不相关的git存储库,保存历史记录 [英] How to combine two unrelated git repositories, preserving history

查看:150
本文介绍了如何组合两个不相关的git存储库,保存历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不太了解git。 : - /



背景



我有两个不相关的基于git的文档存储库,一个存储库。我想保留原始时间戳记(可以追溯到2005年)和个人文件记录。这两个仓库不包含分支,没有文件夹,并且在文件命名方面没有重叠。



在ASCII-land中,它看起来像这样:

  REPO A | ------------------------- | 
REPO B | =============== |

其中重叠表示时间。

目标



我的目标是拉开重叠的时间戳,以便两个回购看起来像是一个不间断的历史记录:

  REPO A + B | ------------------- ==  -  = --- ==== ======== | 



我试过的东西



,我不知道git很好,所以我可能搞砸了一些东西。



首先,我尝试添加更新,更小的回购作为更大,较旧的回购,获取更改,并提交结果。

  MERGE | ---------所有的新回购更改都集中在一个分支中。 -------------------  -  | 
\ =============== /

下一步,我尝试重新绑定(使用 - committer-date-is-author-date ),我认为这会起作用,但是最终我得到一个长的提交历史记录只是将两个回购堆叠在一起。

  REBASE | ------------- ------------ =============== | 

我无法找到重放组合历史的方法。我真的希望rebase会是答案。



我看过的答案




解决方虽然@ codeWizard的回复很有帮助,但这种方法并没有按照我想要的方式保留时间戳。它确实引导了我一个兔子洞,帮助我找到一个解决方案,尽管...


  1. 创建一个新的空白存储库

      git init 


  2. 将旧存储库添加并提取为远程存储

      git remote add -f oldRepoA ../oldRepoA 
    git remote add -f oldRepoB ../oldRepoB


  3. 导出合并的提交历史记录通过timestamp和hash将管道输出到 sort ,通过 cut 丢弃时间戳,然后管理时间顺序列表分类后的散列为 xargs ,它运行一个shell脚本为每个单独的散列导出一个补丁,然后立即将补丁应用到新的repo。

      git log --all --oneline --format =%at%H|排序|剪切-c12- | 
    xargs -I {} sh -c
    'git format-patch -1 {} --stdout |
    git am --committer-date-is-author-date'


- committer-date-is-author-date 是保持原始时间戳的关键。这样做可能会有更好的方式,但是这对我的用例足够好了!


I don't know git very well. :-/

Background

I have two unrelated git-based document repositories that I would like to combine into a single repository. I would like to preserve the original timestamps (dating back to 2005) and individual file histories. The two repos contain no branches, no folders, and there is no overlap in terms of file naming.

In ASCII-land, it looks like this:

REPO A    |-------------------------|
REPO B                    |===============|

Where the overlap denotes time.

Goal

My goal is to "zipper up" the overlapping timestamps so that the two repos look like a single, unbroken history:

REPO A+B  |-------------------==--=---============|

What I've Tried

Again, I don't know git very well, so I could have screwed something up.

First I tried to add the newer, smaller repo as a remote for the larger, older repo, fetch the changes, and commit the result. I ended with all the new repo changes lumped together in a branch after the older repo:

MERGE  |-------------------------                 -|
                                 \===============/

Next I tried rebasing (with --committer-date-is-author-date), which I thought would work, but instead I end up with one long commit history that just stacks the two repos on top of each other.

REBASE |-------------------------===============|

I haven't been able to find a way to "replay" the combined history. I was really hoping rebase would be the answer.

Answers I've Looked At

解决方案

While @codeWizard's reply was helpful, that approach didn't retain the timestamps the way I wanted. It did lead me down a rabbit hole that helped me find a solution though...

  1. Create a new, blank repository

    git init
    

  2. Add and fetch the old repositories as remotes

    git remote add -f oldRepoA ../oldRepoA
    git remote add -f oldRepoB ../oldRepoB
    

  3. Export the combined commit history by timestamp and hash, pipe the output to sort, discard the timestamps via cut, and then pipe the list of chronologically sorted hashes to xargs, which runs a shell script to export a patch for each individual hash and then immediately apply the patch to the new repo.

    git log --all --oneline --format="%at %H" | sort | cut -c12- | 
        xargs -I {} sh -c 
            'git format-patch -1 {} --stdout | 
             git am --committer-date-is-author-date'
    

The --committer-date-is-author-date is key to keeping the original timestamps. There might be a better way of doing this, but this works well enough for my use case!

这篇关于如何组合两个不相关的git存储库,保存历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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