git撤销commit到未提交状态

12.4k 记录 2评论

如何把最后一次提交(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]

2条评论

米豆 says: 回复

经常用到这些命令

歪麦 says: 作者

确实是,记住了工作效率大大提高,不然还得每次找

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

昵称 *