Git squash history after merge

后端 未结 4 1917
春和景丽
春和景丽 2020-12-16 10:53

I merged an upstream of a large project with my local git repo. Prior to the merge I had a small amount of history that was easy to read through, but after the merge a massi

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-16 11:48

    The solution I ended up using was to manually recreate the history. I did this mainly because I didn't want to spend too much time looking for an elegant solution and there wasn't that much history (around 30 commits I'd have to manually merge).

    So, I created a branch before I merged the huge upstream:

    git checkout -b remove-history-fix 
    

    Then re-merged the upstream using the --squash option.

    git merge --squash 
    

    Then manually cherry-picked the commits after the merge from the old branch (the one with the huge amount of upstream history).

    git cherry-pick 
    

    After all those commits were merged into my remove-history-fix branch, I removed the branch with the upstream history.

    git branch -D 
    

提交回复
热议问题