我如何将一个git历史追加到另一个? [英] How do I append one git history to another?
问题描述
我有一个存储库,其中包含旧版网站的代码,该网站不再在 master
上使用。该网站在新的存储库中完全重新设计,并且该存储库中的代码和历史记录被复制到旧网站的存储库中的分支中,我们称之为 new_site
。我无法将 new_site
合并到 master
中,因为历史记录完全不同。
我调查了两个子模块和子树合并了一下,但两者似乎只在您试图保留来自包含在子目录另一个项目,而不是当你想把两棵工作树粘在一起时。
在这一点上,我希望旧代码保持在原来的位置,并在当前HEAD之上追加 new_site
。任何想法如何我可以做到这一点,或替代的建议,清理这个烂摊子,而不会吹走旧代码? 想法是:
- 在如何将两个单独的不相关的Git仓库合并成一个具有单一历史时间表的仓库(fetch + cherry-picking)
-
git clone < git repository B url>
cd< git repository B目录>
git remote add repo -A-branch< git repository目录>
git fetch repo -A-branch master
git remote rm repo -A-branch
从A导入了正确的分支后,您可以使用 移植点 ,然后 git filter-branch
将嫁接历史转化为真实历史,以摆脱嫁接点。
I have a repository that contains the code for an old version of a website that is no longer being used on master
. The site was completely redesigned in a new repository, and the code and history from that repository was copied over into a branch in the repo of the old site, let's call it new_site
. I can't merge new_site
into master
, since the histories are entirely different.
I've investigated both submodules and subtree merges a bit, but both seem to only be relevant when you're trying to keep code from one project contained in a subdirectory of another project, not when you want to stick two working trees on top of each other.
At this point, I would like to have the old code remain where it is, and just append new_site
on top of the current HEAD. Any idea how I can accomplish this, or alternate suggestions for cleaning up this mess without blowing away the old code?
The general idea is:
- explained in "How to combine two separate unrelated Git repositories into one with single history timeline" (fetch + cherry-picking)
implemented in "Concatenate the history of two Git repositories?"
git clone <git repository B url> cd <git repository B directory> git remote add repo-A-branch <git repository A directory> git fetch repo-A-branch master git remote rm repo-A-branch
Once you have imported the right branch from A, you can use graft point, and then git filter-branch
to turn a grafted history into "real" history, to get rid of the graft point.
这篇关于我如何将一个git历史追加到另一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!