随笔 - 224  文章 - 0  评论 - 216  阅读 - 109万

git删除push到远程服务器的commit

如果不小心把不该提交的代码或者敏感的数据(如密码)提交到远程git服务器上,可以使用git reset回滚到上一个commit,并且commit history不留下任何痕迹。

具体做法:

# 1.通过找到想要退回到的commit_id
$ git log
# 2.本地回到上一个commit_id
$ git reset --hard <commit_id>
# 3.推送到服务器,一定要加 --force 参数
$ git push origin HEAD:master --force

如果不加--force参数提交不上去,服务器rejected.

最后你会发现,代码服务器上也不会留下痕迹,完美。

原文首发于 http://fy98.com/2015/09/01/delete-git-server-commit/

posted on   Frank.Fan  阅读(9851)  评论(0编辑  收藏  举报
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示