How can I combine two commits into one commit?

前端 未结 3 702
情歌与酒
情歌与酒 2021-01-29 19:31

I have a branch \'firstproject\' with 2 commits. I want to get rid of these commits and make them appear as a single commit.

The command git merge --squash

3条回答
  •  天涯浪人
    2021-01-29 19:48

    Lazy simple version for forgetfuls like me:

    git rebase -i HEAD~3 or however many commits instead of 3.

    Turn this

    pick YourCommitMessageWhatever
    pick YouGetThePoint
    pick IdkManItsACommitMessage
    

    into this

    pick YourCommitMessageWhatever
    s YouGetThePoint
    s IdkManItsACommitMessage
    

    and do some action where you hit esc then enter to save the changes. [1]

    When the next screen comes up, get rid of those garbage # lines [2] and create a new commit message or something, and do the same escape enter action. [1]

    Wowee, you have fewer commits. Or you just broke everything.


    [1] - or whatever works with your git configuration. This is just a sequence that's efficient given my setup.

    [2] - you'll see some stuff like # this is your n'th commit a few times, with your original commits right below these message. You want to remove these lines, and create a commit message to reflect the intentions of the n commits that you're combining into 1.

提交回复
热议问题