git 时删除一个提交

由于手贱把代码里写了一些敏感数据被无意中提交到了 github,这时最好把最近一次的 commit 删掉,做法是这样的。

git log看一下最近的 commit_id ,比如如下:

 commit 3ba6d28dbb9b451846daeedb562350eefe2a3eb6 Author: realityone <[email protected]> Date: Sat Apr 26 08:07:58 2014 +0800 = = 
commit 0ff2cf3da49e7dbfc8328ac61ece6f5c5c44c032 Author: realityone <[email protected]> Date: Fri Apr 25 18:15:25 2014 +0800 小修改

我要回到某个时候就复制那个 commit_id ,然后用

git reset --hard 0ff2cf3da49e7dbfc8328ac61ece6f5c5c44c032

的命令退回那个时候的代码,接下来再用

git push origin HEAD --force

命令进行提交,github 上的代码也会退回那个时候。

Tags :