代码之家  ›  专栏  ›  技术社区  ›  mathk

Git取消还原

  •  19
  • mathk  · 技术社区  · 15 年前

    在git中,假设我提交了A和B

    A---[B]
    

    但后来我又用

    git revert HEAD
    

    所以我现在在那里:

    [A]---B
    

    3 回复  |  直到 11 年前
        1
  •  73
  •   pal4life    10 年前

    一般有两种选择:

    • 还原还原提交(创建第二个还原提交,使您返回到原始状态)

    git reset—硬头^

    第二种选择只适用于

    git重置--硬

    在不创建任何还原提交的情况下回滚。

        2
  •  12
  •   WesternGun    5 年前

    如果你还没有完全做到,也就是说,在 gitbash

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

    那你可以用 git revert --abort 中止。

    如果你做到了。。只是不要重置,更改仍然存在。使用 git reset 改变状态。而不是 --hard ,也可以使用 --soft (保留所有更改)。

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

    此外,如果要还原多个提交:

    git reset --soft HEAD~3 // discart last 3 commits. Don't know if it works for commits of others.
    
        3
  •  2
  •   Amal Augustine Jose elp    5 年前

    当你创建一个新的 commit 哪一个 reverts another commit 你可以把它当作一个正常的承诺。

    所以基本上你有很多选择,比如

    • git rebase -i
    • git reset --hard <commitID> (在还原之前重置为提交, )
    • git reset --soft <commitID> (同上,但保留局部更改)
    • 从技术上讲你可以使用 git revert <commitId> 恢复您的恢复