How to revert multiple git commits?

后端 未结 13 2584
被撕碎了的回忆
被撕碎了的回忆 2020-11-22 07:36

I have a git repository that looks like this:

A <- B <- C <- D <- HEAD

I want the head of the branch to point to A, i.e. I want B

13条回答
  •  一整个雨季
    2020-11-22 08:00

    I really wanted to avoid hard resets, this is what I came up with.

    A -> B -> C -> D -> HEAD
    

    To go back to A (which is 4 steps back):

    git pull                  # Get latest changes
    git reset --soft HEAD~4   # Set back 4 steps
    git stash                 # Stash the reset
    git pull                  # Go back to head
    git stash pop             # Pop the reset 
    git commit -m "Revert"    # Commit the changes
    

提交回复
热议问题