How to revert a merge commit that's already pushed to remote branch?

后端 未结 17 1668
无人及你
无人及你 2020-11-22 07:04

git revert alone won\'t work. -m must be specified, and I\'m pretty confused about it.

Anyone experienced this before?<

17条回答
  •  失恋的感觉
    2020-11-22 07:54

    The correctly marked answer worked for me but I had to spend some time to determine whats going on.. So I decided to add an answer with simple straightforward steps for cases like mine..

    Lets say we got branches A and B.. You merged branch A into branch B and pushed branch B to itself so now the merge is part of it.. But you want to go back to the last commit before the merge.. What do you do?

    1. Go to your git root folder (the project folder usually) and use git log
    2. You will see the history of recent commits - the commits have commit/author/date properties while the merges also have a merge property - so you see them like this:

      commit: Merge: Author: Date:

    3. Use git log and git log - you will see the commit histories of those parent branches - the first commits in the list are the latest ones

    4. Take the of the commit you want, go to your git root folder and use git checkout -b - that will create a new branch starting from that last commit you've chosen before the merge.. Voila, ready!

提交回复
热议问题