Git squash history after merge

后端 未结 4 1907
春和景丽
春和景丽 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:46

    I was able to squash several commits after multiple merges from the master branch using the strategy found here: https://stackoverflow.com/a/17141512/1388104

    git checkout my-branch            # The branch you want to squash
    git branch -m my-branch-old       # Change the name to something old
    git checkout master               # Checkout the master branch
    git checkout -b my-branch         # Create a new branch
    git merge --squash my-branch-old  # Get all the changes from your old branch
    git commit                        # Create one new commit
    

    You will have to force an update if you need to push your squashed branch to a remote repository that you have previously pushed to, e.g. git push origin my-branch -f

提交回复
热议问题