提交项目后回滚Git状态到首次提交
情景描述 在将项目share到github后(已经push),发现push的文件中含有敏感的信息,所以想回滚状态到之前的版本。但使用log命令可以发现当前仅有一个commit状态: Yitian-MacBook-Pro:springboot-learning yitian$ git log commit f8e6d2455c8f494b860d0bb9a4b103624d75ef2a (HEAD -> master, origin/master) Author: yitian <yitian.z@foxmail.com> Date: Sat Feb 1 20:49:07 2020 +0800 init commit 使用reset命令无法回退到上次的提交状态(因为仅有一次提交,HEAD^状态并不存在),所以该方法不行。 解决方法 执行下面的命令,清除所有提交的版本并清空工作空间,这样就可以再进行第一次提交了: git update-ref -d HEAD 执行之后,将文件中敏感信息去掉之后commit并push,应该会出现如下的问题: Yitian-MacBook-Pro:springboot-learning yitian$ git push To https://github.com/Yitian-Zhang/springboot-learning.git !