Git: How to squash all commits on branch

前端 未结 13 1939
情深已故
情深已故 2020-12-04 04:33

I make new branch from master with:

git checkout -b testbranch

I make 20 commits into it.

Now I want to squash those

13条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-04 05:00

    Based on reading several Stackoverflow questions and answers on squashing, I think this is a good one liner to squash all commits on a branch:

    git reset --soft $(git merge-base master YOUR_BRANCH) && git commit -am "YOUR COMMIT MESSAGE" && git rebase -i master
    

    This is assuming master is the base branch.

提交回复
热议问题