How do I append one git history to another?
Asked Answered
B

2

8

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?

Barge answered 7/2, 2014 at 8:1 Comment(0)
K
10

The general idea is:

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.

Kessia answered 7/2, 2014 at 9:0 Comment(0)
O
3

I wrote this script a while ago, which handles a common case for this (append a repository's history to another repository in a subdirectory):

https://github.com/multi-io/utils/blob/master/git-append-repo

Overexpose answered 25/4, 2018 at 21:14 Comment(2)
Interesting script, more detailed than my answer. +1Kessia
This script works like a charm, you just need to 'master' to 'main' if that is your case! thanks !!Trossachs

© 2022 - 2024 — McMap. All rights reserved.