Git cancel a revert

前端 未结 3 778
半阙折子戏
半阙折子戏 2020-12-29 19:32

In git let say I commit A and B

A---[B]

But then I revert with

git revert HEAD

So I am there now:

3条回答
  •  长发绾君心
    2020-12-29 20:25

    If you haven't done it completely, i.e., in gitbash you see something like:

    Username@Host MINGW64 /d/code/your-project (feature|REVERTING)
    

    then you can use git revert --abort to abort.

    If you have done it.. just don't reset, the changes are still there. Use git reset to change the state. Instead of --hard, you can also use --soft(keep all the changes).

    git reset --soft HEAD^ // discard the last commit, keeping all the changes after that
    

    Also, if you want to revert more than 1 commits:

    git reset --soft HEAD~3 // discart last 3 commits. Don't know if it works for commits of others.
    

提交回复
热议问题