歪麦博客

git撤销commit到未提交状态

如何把最后一次提交(commit)的所有文件撤销回Changes not stagedUntracked files状态呢?

分有3种情况:

情况一:把最后的commit切回Changes to be committed(绿色)状态,使用命令:

git reset --soft HEAD^

注意:Windows系统需要在^符号两边加上引号,如下:

git reset --soft HEAD"^"

情况二:把最后的commit切回Changes not staged for commit(红色)状态,使用命令:

git reset HEAD^

情况三Changes to be committed(绿色)状态切回Changes not staged for commit(红色)状态,使用命令:

git reset HEAD <file>...          # 单个文件
git reset HEAD -- .               # 所有Changes to be committed的文件

最后一条命令在git命令行也有提示,不需要记住。

参考资料:

  1. Move (or “Undo”) last git commit to unstaged area [duplicate]
退出移动版