How to revert multiple git commits?

后端 未结 13 2594
被撕碎了的回忆
被撕碎了的回忆 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 07:42

    For doing so you just have to use the revert command, specifying the range of commits you want to get reverted.

    Taking into account your example, you'd have to do this (assuming you're on branch 'master'):

    git revert master~3..master
    

    or git revert B...D or git revert D C B

    This will create a new commit in your local with the inverse commit of B, C and D (meaning that it will undo changes introduced by these commits):

    A <- B <- C <- D <- BCD' <- HEAD
    

提交回复
热议问题