want to squash multiple commits in github

前端 未结 1 1436
天涯浪人
天涯浪人 2021-02-15 13:16

I want to squash two latest commits with commit messages \"first\" and \"second\". First I pull master then I use the command

git rebase -i HEAD~2 master


        
相关标签:
1条回答
  • 2021-02-15 13:33

    git rebase rewrites history, because the commits were modified. It's not a problem when the said commits haven't been pushed to a remote repository, but here the remote was previously pushed with the commits you rewrote, so it rejected the push.

    When you pulled from github, it merged both histories, and applied your squash commit, hence the mess.

    Conclusion: when you want to rewrite commits that has already been pushed, you have two options:

    • don't do it
    • do a git push --force, which will rewrite history also on the remote, and tell people that you have rewrote history, so they'll see strange things on their next pull.
    0 讨论(0)
提交回复
热议问题