如何将一个Git存储库重新绑定到另一个? [英] How to rebase one Git repository onto another one?

查看:101
本文介绍了如何将一个Git存储库重新绑定到另一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Git仓库(A),它包含一个项目的开发,直到某个点。然后我丢失了这个回购A的USB棒。幸运的是我有最新的提交备份,所以我可以在稍后导入最新项目状态并继续开发的情况下创建新的存储库(B)。
现在我恢复了丢失的U盘,所以我有两个Git仓库。



我想我必须将repo B重新设置为repo A,但是我如果A和B不是相同的回购(您使用最新的工作副本创建了B),则必须使用嫁接假设他们有共同的历史。



假设您已经按照VonC's answer ,回购看起来像这样 1

 〜/ B $ git tnylog 
* 6506232(HEAD,master)B
* 799d6ae的最新工作从USB棒进口备份
〜/ B $ git tnylog A / master
* 33b5b16(A / master)A
*的头部6092517初始提交

创建一个告诉根的移植B的父母是A的头:

  echo'799d6aeb41095a8469d0a12167de8b45db02459c 33b5b16dde3af6f5592c2ca6a1a51d2e97357060'\ 
>> .git / info / grafts

现在当您请求历史记录时,上面的两个历史记录将显示为一个历史记录B.使移植永久化是一个简单的 git filter-branch ,没有参数。但是,在过滤分支之后,你不在任何分支上,所以你应该 git branch -D master; git checkout -b master






1 git tnylog = git log --oneline --graph --decorate

I had one Git repository (A) which contains the development of a project until a certain point. Then I lost the USB stick this repo A was on. Luckily I had a backup of the latest commit, so I could create a new repository (B) later where I imported the latest project's state and continue development. Now I recovered that lost USB stick, so I have two Git repositories.

I think I just have to rebase repo B onto repo A somehow, but I have no idea how to do that, maybe using fetch/pull and rebase?

解决方案

If A and B are not the same repo (you created B by using the latest working copy you had), you have to use a graft to pretend that they have common history.

Let’s assume you’ve added A as a remote for B as per VonC’s answer, and the repo looks like this1:

~/B$ git tnylog 
* 6506232 (HEAD, master) Latest work on B
* 799d6ae Imported backup from USB stick
~/B$ git tnylog A/master
* 33b5b16 (A/master) Head of A
* 6092517 Initial commit

Create a graft telling the root of B that its parent is the head of A:

echo '799d6aeb41095a8469d0a12167de8b45db02459c 33b5b16dde3af6f5592c2ca6a1a51d2e97357060' \
 >> .git/info/grafts

Now the two histories above will appear as one when you request the history for B. Making the graft permanent is a simple git filter-branch with no arguments. After the filter-branch, though, you aren’t on any branch, so you should git branch -D master; git checkout -b master.


1 git tnylog = git log --oneline --graph --decorate

这篇关于如何将一个Git存储库重新绑定到另一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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