Git reset
如果已经commit
但是还没有push
的时候,想要撤消刚才的提交(我有时会遇到这样的情况),
可以用reset
命令来实现:
先用status
命令查看一下当前的状态:
$ git status
On branch main
Your branch is ahead of 'origin/main' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
然后,用reset
命令进行回退:
$ git reset --soft HEAD~
最后,再查看回退后的状态:
$ git status
On branch main
Your branch is up to date with 'origin/main'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: 2021-11-17-c-function-pointer.md
以上。