Git: How to squash all commits on branch

前端 未结 13 1947
情深已故
情深已故 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:07

    All this git reset, hard, soft, and everything else mentioned here is probably working (it didn't for me) if you do the steps correctly and some sort of a genie.
    If you are the average Joe smo, try this:
    How to use git merge --squash?


    Saved my life, and will be my go to squash, been using this 4 times since I found out about it. Simple, clean and basically 1 comamnd. In short:


    If you are on a branch lets call it "my_new_feature" off develop and your pull request has 35 commits (or however many) and you want it to be 1.

    A. Make sure your branch is up to date, Go on develop, get latest and merge and resolve any conflicts with "my_new_feature"
    (this step really you should take as soon as you can all the time anyway)

    B. Get latest of develop and branch out to a new branch call it "my_new_feature_squashed"

    C. magic is here.
    You want to take your work from "my_new_feature" to "my_new_feature_squashed"
    So just do (while on your new branch we created off develop):
    git merge --squash my_new_feature

    All your changes will now be on your new branch, feel free to test it, then just do your 1 single commit, push, new PR of that branch - and wait for repeat the next day.
    Don't you love coding? :)

提交回复
热议问题