Squash my last X commits together using Git

前端 未结 30 4070
醉酒成梦
醉酒成梦 2020-11-21 05:17

How can I squash my last X commits together into one commit using Git?

30条回答
  •  生来不讨喜
    2020-11-21 05:38

    Anomies answer is good, but I felt insecure about this so I decided to add a couple of screenshots.

    Step 0: git log

    See where you are with git log. Most important, find the commit hash of the first commit you don't want to squash. So only the :

    Step 1: git rebase

    Execute git rebase -i [your hash], in my case:

    $ git rebase -i 2d23ea524936e612fae1ac63c95b705db44d937d
    

    Step 2: pick / squash what you want

    In my case, I want to squash everything on the commit that was first in time. The ordering is from first to last, so exactly the other way as in git log. In my case, I want:

    Step 3: Adjust message(s)

    If you have picked only one commit and squashed the rest, you can adjust one commit message:

    That's it. Once you save this (:wq), you're done. Have a look at it with git log.

提交回复
热议问题