Merge two Git repos and keep the history

后端 未结 3 950
眼角桃花
眼角桃花 2020-12-04 22:41

I want to extend on another question I had: Merge two Git repositories and keep the master history

I have succeeded in merging 2 different repo\'s into one repo. I n

3条回答
  •  醉梦人生
    2020-12-04 23:34

    This answer suggests a different way to use RepoB as the active repo, and still have access to RepoA history :

    use git replace

    # start with a regular clone of the active repo :
    $ git clone RepoB
    
    # add repoA as a remote :
    $ git remote add -f history https://github.com/DimitriDewaele/RepoA
    
    # get hash of *initial* commit on repoB :
    $ git log --oneline origin/master | tail -1
    abcdef Initial commit
    
    # get hash of last commit on repoA :
    $ git log --oneline history/master | head -1
    12345 Merge branch 'develop'
    
    # use 'git replace' to tell git to stitch histories in the log :
    $ git replace abcdef 12345
    

    Note : this operation is done on your machine, not on the remote repositories, so should be repeated on all new clones.

    Variant :

    You may push RepoA:master to RepoB under a new name (e.g : RepoB:history/master), then you can use git replace abcdef history/master, on commits which are all stored in RepoB.

提交回复
热议问题