Squash my last X commits together using Git

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

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

30条回答
  •  遇见更好的自我
    2020-11-21 05:28

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

    git rebase -i HEAD~X
    

    The following content will be shown:

    pick 1bffc15c My earlier commit
    pick 474bf0c2 My recent commit
    
    # ...
    

    For the commits that you want to squash, replace pick with fixup, so it becomes:

    pick 1bffc15c My earlier commit
    fixup 474bf0c2 My recent commit
    
    # ...
    

    If it's open in vim (default interface within terminal), then press Esc on your keyboard, type :wq and Enter to save the file.

    Verify: Check git log

提交回复
热议问题