Git撤销最后一次提交
Git可以使用reset重置来撤销提交。
方法一
撤销最后一次提交
git reset HEAD~1
执行后,状态重置为上一次提交,且撤回提交的文件的状态变回unstaged,即文件没有被git跟踪。
示例
$ git commit -m 'add test.html'
[master ade6d7e] add test.html
1 file changed, 1 insertion(+)
create mode 100644 test.html
$ git reset HEAD~1
$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
test.html
nothing added to commit but untracked files present (use "git add" to track)
撤回后test.html为Untracked files。
方法二
git reset --soft HEAD~1
使用--soft,执行后,状态重置为上一次提交,但撤回提交的文件add到git,被git跟踪。
示例
$ git commit -m 'add test.html'
[master 877b8f0] add test.html
1 file changed, 1 insertion(+)
create mode 100644 test.html
$ git reset --soft HEAD~1
clcaza@clcaza MINGW64 /d/webstormProjectsDemo/ngcli-demo (master)
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: test.html
test.html状态为Changes to be committed