合并两个git存储库以获取线性历史记录 [英] Merging two git repositories to obtain linear history

查看:136
本文介绍了合并两个git存储库以获取线性历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  ftp  - >我有两个git存储库和它们之间的许多未跟踪的更改: C--(未跟踪变化) -  D 
/ \
git A - B - C < - old / master \
\
\
new / master - > D - E - F

如何将旧版本库合并到新版本库中以获得线性历史记录像

  A  -  B  -  C  -  D  -  E  -  F 



灵感源自如何将Git存储库合并为线性历史记录?



我已经完成:

  git clone url:// new新
cd新/
git远程添加旧url:// old
git fetch old
git reset --hard origin / master
git filter-branch - parent-filter'seds_ ^ \ $ _- p old / master_'HEAD
git push origin master

唯一的问题是每个新/主提交都加倍(因为我认为父变化),所以我现在(M是合并提交)

  D --- E --- F-- 
\
A - B - C - D' - E' --F' - M

如何轻松删除不必要的提交(D - F,也许M )?

解决方案

只需查看您的分支并运行:

  git reset --hard ** SHA-OF-F'** 

这会从你的帐户中删除 M D - F 分行。


I have two git repositories and a lot of untracked changes between them:

   ftp -->            C-- (untracked changes) --D
                     /                           \
   git        A--B--C <-- old/master              \
                                                   \
                                                    \
                                  new/master -->     D--E--F 

How can I merge old repository into new repository to have a linear history like

A--B--C--D--E--F

EDIT:

inspired by How can I combine Git repositories into a linear history?

I've done:

git clone url://new new
cd new/
git remote add old url://old
git fetch old
git reset --hard origin/master
git filter-branch --parent-filter 'sed "s_^\$_-p old/master_"' HEAD
git push origin master

Only problem is that every commit from new/master was doubled (due to change of parent I think) so I've now (M is merge commit)

         D---E---F--         
                    \
A--B--C--D'--E'--F'--M 

How can I easily remove unnecessary commits (D - F and maybe M)?

解决方案

Just check out your branch and run:

  git reset --hard **SHA-OF-F'**

That will remove M and D-F from your branch.

这篇关于合并两个git存储库以获取线性历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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