What is the difference between git reset and git revert?

前端 未结 2 1116
后悔当初
后悔当初 2021-02-14 08:25

Hi I am a newbie to git and I don\'t understand what is the basic difference between git reset and git revert. Does git revert reverts the

2条回答
  •  猫巷女王i
    2021-02-14 08:45

    As far as I know, they are doing totally different thing.

    git revert aimed to revert effects of previous commit. For example,

    A <- B <- C 
              ^ HEAD
    

    If I found B I committed before is wrong, and I want to "undo" its change, git-revert-ing B will cause:

    A <- B <- C <- B'
                   ^ HEAD
    

    for which B' is reversing the change done in B.

    git reset is more straight-forward, it is simply setting the HEAD to a certain commit,

    A <- B <- C 
              ^ HEAD
    

    git-reset-ting to B will give you

    A <- B <- C 
         ^ HEAD
    

提交回复
热议问题