将历史记录添加到git存储库或合并git存储库 [英] add history to git repository or merge git repositories

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

问题描述

大家通过merge git repositories了解不同的东西,所以这是我的情况。我们有一个TFS仓库,我们已经在一个时间点检查了资源并做了一个初始的git commit。然后我们在git中进行了正常的开发(分支,合并等)。问题是,在新的存储库中,我们没有在git仓库中存在历史记录,我们希望解决这个问题。因此,我已将整个TFS存储库转换为git存储库,现在我需要将转换后的TFS存储库与当前的git存储库合并。



从以上描述可以明显看出,存储库是独立于git的立场,但从逻辑角度来看,它们有一个共同的提交(提交成为当前git存储库的初始提交)。

如何合并这些回购没有失去其中任何一个的历史?我可以将转换后的TFS回购作为基础,然后樱桃选择当前回购的主变更,但不会导入在当前回购中创建的所有分支。

解决方案

编辑:我之前的回答并没有导致任何好处。 git rebase不是为了做到这一点。
然而,类似的东西已经发生在stackoverflow上:合并两个git仓库以获得线性历史记录



您可以尝试以下过程:

  git init合并
cd合并
git remote添加旧url:/ to / old
git remote添加新url:/ to / new
git remote update

您将拥有一个新的回购库,并引用了两个库。然后

  git reset --hard old / master 

这将使主分支指向旧回购的主分支。
现在你可以选择从新的repo的master分支中提交所有的提交

  git cherry-pick< sha-第一次提交新回购的第一个> .. new / master 

我们是我们开始的:master分支没问题,但新回购的其他分支呢?
好​​吧,你不需要旧的repo了,所以

  git remote rm old 
code>

然后,假设您的新存储库中有一个名为'branch1'的分支。

  git checkout branch1 
git rebase master

这应该改变branch1的历史记录,让它从master(master master,包含导入仓库中的历史记录)开始,并且rebasing应该发生而不会发生冲突。
检查历史记录与gitk一致,然后您可以使用

  git push -f new master 
git push -f new branch1

在强制推送之前,您必须确定历史记录是可以的,因为这将改变上游的历史(如果需要的话,保留旧的和旧的回购的备份)

Everybody understands something different by "merge git repositories", so here is my case. We had a TFS repository and we have checked out the sources at one point in time and made an initial git commit. Then we did normal development in git (branching, merging, etc.). The problem is that in the new repository we do not have history in out git repository and we would like to fix that. Therefore I have converted whole TFS repository to git repository and now I need to merge the converted TFS repository with the current git repository.

As becomes obvious from the above description the repositories are independent from git standpoint, but from logical point of view they have one commit in common (the commit that became initial commit to current git repository).

How do I merge those repos without losing history of any of them? I could just take the converted TFS repo as base and then cherry pick changes from master of the current repo, but that would not import all the branches that were created in the current repo.

解决方案

EDIT: my previous answer does not lead to nothing good. git rebase was not meant to do this. However, something similar already happened on stackoverflow: Merging two git repositories to obtain linear history

You can try with this procedure:

git init combined
cd combined
git remote add old url:/to/old
git remote add new url:/to/new
git remote update

You will have a new repo, with references to both repos. then

git reset --hard old/master

This will make the master branch point to the master branch of the old repo. You can now cherry pick all commits from the master branch of new repo

git cherry-pick <sha-1 of first commit on new repo>..new/master

We are were we started: master branch is ok, but what about other branches in the new repo? Well, you do not need your old repo anymore, so

git remote rm old

then, say you have a branch named 'branch1' in your new repository.

git checkout branch1
git rebase master

This should change history of branch1 to make it start from master (the combined master, containing history from your imported repo), and rebasing should happen without conflicts. Check history is consistent with gitk, then you can force push with

git push -f new master
git push -f new branch1

You have to be sure that history is ok before forcing push, since this will change history upstream (keep a backup of both new and old repos to recover if needed)

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

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