Careful: git reset --hard
WILL DELETE YOUR WORKING DIRECTORY CHANGES .
(小心: git reset --hard
将删除您的工作目录更改 。)
Be sure to stash any local changes you want to keep before running this command. (在运行此命令之前,请确保存储要保留的所有本地更改 。)
Assuming you are sitting on that commit, then this command will wack it...
(假设您正坐在该提交上,那么此命令将使其失效...)
git reset --hard HEAD~1
The HEAD~1
means the commit before head.
(HEAD~1
表示在head之前提交。)
Or, you could look at the output of git log
, find the commit id of the commit you want to back up to, and then do this:
(或者,您可以查看git log
的输出,找到要备份到的提交的提交ID,然后执行以下操作:)
git reset --hard <sha1-commit-id>
If you already pushed it, you will need to do a force push to get rid of it...
(如果您已经推过它,则将需要用力推动才能摆脱它...)
git push origin HEAD --force
However , if others may have pulled it, then you would be better off starting a new branch.
(但是 ,如果其他人可能已经撤消了,那么您最好开始新的分支。)
Because when they pull, it will just merge it into their work, and you will get it pushed back up again. (因为当他们拉动它时,它只会将其合并到他们的工作中,并且您会再次将其推回去。)
If you already pushed, it may be better to use git revert
, to create a "mirror image" commit that will undo the changes.
(如果已经推送了,最好使用git revert
创建一个“镜像”提交,以撤消更改。)
However, both commits will be in the log. (但是,两个提交都将在日志中。)
FYI -- git reset --hard HEAD
is great if you want to get rid of WORK IN PROGRESS.
(仅供参考-如果您想摆脱正在进行的工作,则git reset --hard HEAD
非常git reset --hard HEAD
。)
It will reset you back to the most recent commit, and erase all the changes in your working tree and index. (它会将您重置为最新提交,并清除工作树和索引中的所有更改。)
Lastly, if you need to find a commit that you "deleted", it is typically present in git reflog
unless you have garbage collected your repository.
(最后,如果您需要查找“删除”的提交,除非您已垃圾回收存储库,否则它通常存在于git reflog
。)