Git: How to squash all commits on branch

前端 未结 13 1932
情深已故
情深已故 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条回答
  •  Happy的楠姐
    2020-12-04 04:58

    Checkout the branch for which you would like to squash all the commits into one commit. Lets say its called feature_branch.

    git checkout feature_branch
    

    Step 1:

    Do a soft reset of your origin/feature_branch with your local master branch (depending on your needs, you can reset with origin/master as well). This will reset all the extra commits in your feature_branch, but without changing any of your file changes locally.

    git reset --soft master
    

    Step 2:

    Add all of the changes in your git repo directory, to the new commit that is going to be created. And commit the same with a message.

    git add -A && git commit -m "commit message goes here"
    

提交回复
热议问题