combining unrelated git repositories retaining history/branches

前端 未结 3 1158
情话喂你
情话喂你 2021-01-04 12:12

we\'re having 3 separate git repositories (each with some branches) which we\'d like to combine into one keeping full history and the ability to access the branches, like so

3条回答
  •  走了就别回头了
    2021-01-04 12:36

    You don't want submodules as you will pull your hair out with all the git submodule update commands you will be issuing. You will also have to issue 3 git log commands instead of one to see what has happened in a certain amount of time.

    Bring all of the histories into one repo. Use filter-branch to reset the directories that each repos history resides in. There is no need to stitch. You can simply merge at any point once you do the filter branch.

    Essentially repoA/master, repoB/master and repoC/master will exist in the new repo you make (although you can just start with one of them). After you apply filter branch, each tree in each commit will have a new root node that will be a directory (A for repoA branches, B for repoB branches, etc).

    OR

    git checkout -b newbranch --root
    git log --all --format=%ad%H | sort | cut -c10- | xargs -n 1 git cherry-pick
    

    adjust the cut so it only takes the hash. Haven't tried this but let me know how it works. You may need to flatten out history first with rebase. You can't interleave the different branches and merges from the 3 different histories.

    hope this helps.

提交回复
热议问题