合并两个git存储库-一致的历史记录 [英] merge two git repositories - consistent history

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

问题描述

我找到了一些类似的主题,但是请看一下我的解决方案.看起来git子树旨在解决稍微不同的问题.我有两个存储库A和B.存储库B仅具有一个与存储库A内容无关的目录.我只想将该目录添加到repo A,并在repoA中拥有一个一致的历史记录.存储库B将不再使用.

I have found a few similar topics but please take a look at my solution. It looks like git subtree is intended to solve a slightly different problem. I have two repositories A and B. Repo B has only one directory which is unrelated with the repo A content. I only want to add that directory to repo A and have one consistent history in repoA. Repo B will not be used anymore.

以下是步骤:

cd RepoB
git checkout develop
git remote set-url origin RepoA
git pull origin develop
git push -u origin develop

git pull将执行合并,我应该使用fetch然后与某些选项参数合并吗?

git pull will performed merge, should I use fetch and then merge with some option parameter ?

您还有其他建议吗?

推荐答案

您可以尝试在RepoA的基础上重新构建RepoB:

You can try to rebase RepoB ontop of RepoA:

repoA/master:  A--B--C--D
repoB/master:  X--Y--Z

Result: A--B--C--D--X--Y--Z

通过运行

cd repoA
git remote add repoB git@server:repoB
git fetch repoB
git checkout repoB/master  # replace branch name if needed
git rebase master  # replace branch name if needed

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

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