Skip to content

Instantly share code, notes, and snippets.

@hongyangqin
Last active January 5, 2018 16:24
Show Gist options
  • Save hongyangqin/d981402f50da1ce85e73168a28ad63a6 to your computer and use it in GitHub Desktop.
Save hongyangqin/d981402f50da1ce85e73168a28ad63a6 to your computer and use it in GitHub Desktop.
Git如何删除版本库中的一个提交?

Git如何删除版本库中的一个提交?

from : https://segmentfault.com/q/1010000000115900

git reset --hard HEAD~1
git push --force

如果不小心在测试代码中写上了用户名和密码,而且已经commit到git中,那么我要怎么把这次commit删除掉,让它在历史中不会出现?

:git checkout -- file可以丢弃工作区的修改;

:git reset HEAD file可以把暂存区的修改撤销掉,重新放回工作区状态;

:git reset --hard HEAD^回退到“add distributed”版本时的状态;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment