Squash my last X commits together using Git

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

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

30条回答
  •  北海茫月
    2020-11-21 05:48

    I recommend avoiding git reset when possible -- especially for Git-novices. Unless you really need to automate a process based on a number of commits, there is a less exotic way...

    1. Put the to-be-squashed commits on a working branch (if they aren't already) -- use gitk for this
    2. Check out the target branch (e.g. 'master')
    3. git merge --squash (working branch name)
    4. git commit

    The commit message will be prepopulated based on the squash.

提交回复
热议问题