gitgit-rewrite-history

How to concatenate two git histories


I have a Repository that was imported a year ago into gitlab without any history (commits), just copied into a new Repo.

Now 2 Years later, someone is missing the History.

How can i add the History from the original repo to the imported one?

I followed this Post: concatenate-two-git-histories.

It worked for me, but git shows me that grafts are obsolete. So I`m looking for a more future safe Method.


Solution

  • "Replaced objects" are the new generic method. You can use git replace --graft to have it generate a graft-like replacement which adds a parent to the specified object, or git replace --edit to manually tweak the commit data.

    git replace --graft <base_commit_of_new_history> <parent_to_add>
    

    Like grafts, the replaced objects remain a local override and do not permanently alter the history (though unlike grafts, they can be manually pushed/fetched).

    To make the changes permanent, run a git filter-branch or git filter-repo (no need to specify any filter operations). This will rewrite commits to 'bake in' the replacements. Note that doing so will change commit IDs of the "new" half of the history.