如果已经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

以上。