Squash my last X commits together using Git

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

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

30条回答
  •  梦毁少年i
    2020-11-21 05:46

    To do this you can use following git command.

     git rebase -i HEAD~n
    

    n(=4 here) is the number of last commit. Then you got following options,

    pick 01d1124 Message....
    pick 6340aaa Message....
    pick ebfd367 Message....
    pick 30e0ccb Message....
    

    Update like below pick one commit and squash the others into the most recent,

    p 01d1124 Message....
    s 6340aaa Message....
    s ebfd367 Message....
    s 30e0ccb Message....
    

    For details click on the Link

提交回复
热议问题