若是不当心把不应提交的代码或者敏感的数据(如密码)提交到远程git服务器上,能够使用git reset
回滚到上一个commit,而且commit history
不留下任何痕迹。git
具体作法:bash
# 1.经过找到想要退回到的commit_id $ git log # 2.本地回到上一个commit_id $ git reset --hard <commit_id> # 3.推送到服务器,必定要加 --force 参数 $ git push origin HEAD:master --force
若是不加--force
参数提交不上去,服务器rejected.
服务器
最后你会发现,代码服务器上也不会留下痕迹,完美。code
原文首发于 http://fy98.com/2015/09/01/delete-git-server-commit/server