问题描述
我做了'git commit',但我没有推到其他人。
所以当我做'git status'的时候,我得到了'#你的分支在1次提交之前是'master'。'
实际上,当您使用 git reset 时,您应该参考您正在重置的提交 ;因此您可能需要 db0c078 提交。
一个更简单的版本会是 git reset --hard HEAD ^ ,重置为当前头部之前的提交;这样您就不会必须复制提交ID。
当您执行任何 git reset --hard 时,请小心,因为您可能会丢失任何未提交的更改。您可能需要检查 git status 以确保您的工作副本是干净的,或者您确实想要清除那里的任何更改。
此外,您可以使用 origin / master 作为参考,而不是使用HEAD,如@bdonlan在注释中所建议的: git reset --hard origin / master
I did a 'git commit' but I have not pushed to others. so when i do 'git status', I get '# Your branch is ahead of 'master' by 1 commit.'
So if I want to roll back my top commit, can I just do"
git reset --hard eb27bf26dd18c5a34e0e82b929e0d74cfcaab316given that when i do 'git log'
commit eb27bf26dd18c5a34e0e82b929e0d74cfcaab316 Date: Tue Sep 29 11:21:41 2009 -0700 commit db0c078d5286b837532ff5e276dcf91885df2296 Date: Tue Sep 22 10:31:37 2009 -0700解决方案Actually, when you use git reset, you should refer to the commit that you are resetting to; so you would want the db0c078 commit, probably.
An easier version would be git reset --hard HEAD^, to reset to the previous commit before the current head; that way you don't have to be copying around commit IDs.
Beware when you do any git reset --hard, as you can lose any uncommitted changes you have. You might want to check git status to make sure your working copy is clean, or that you do want to blow away any changes that are there.
In addition, instead of HEAD you can use origin/master as reference, as suggested by @bdonlan in the comments: git reset --hard origin/master
这篇关于删除未推送的git提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!