Why is git revert telling me “bad revision” when I use a commit hash?

巧了我就是萌 提交于 2020-01-01 10:09:56

问题


I am trying to revert to an earlier git commit but get the error "bad revision". Why?

Here is a transcript (with author names removed):

Ellen@ELLEN-PC /c/Users/Susan Mills/git/hello-github (master)
$ git status
# On branch master
nothing to commit, working directory clean

Ellen@ELLEN-PC /c/Users/Susan Mills/git/hello-github (master)
$ git log | head
commit e3eb30cc7ca6d4cd10de755b63821cad75da1e83
Date:   Wed Feb 5 17:54:32 2014 -0800

    I changed my greeting.

commit 063ac580e28bab524286dac7b0a8f88d9e7d365f
Date:   Mon Feb 3 07:53:19 2014 -0800

Ellen@ELLEN-PC /c/Users/Susan Mills/git/hello-github (master)
$ git revert 9e7d365f
fatal: bad revision '9e7d365f'

Why am I getting "bad revision", and what should I do? I am using git bash on Windows 7 with my origin on github.


回答1:


When you use the short version of a SHA1, you use the prefix, not the suffix. So you actually want to say:

git revert 063ac580



回答2:


Use the beginning of the hash as identification, as in:

git revert 063ac580e2



回答3:


You are trying to revert that doesn't exist. The SHA that starts with 9e7d365f is not in your repository.



来源:https://stackoverflow.com/questions/21608432/why-is-git-revert-telling-me-bad-revision-when-i-use-a-commit-hash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!