Git:需要一个修订错误


101

我在项目中初始化了一个新的git,到目前为止,我只有两次提交。我的日志如下

git log
commit e515e5b8dcbd8f1ea4a7a7d4a1efb82a1a0aee7a
Author: Olkun Mustafa <olkun.mustafa@gmail.com>
Date:   Fri Oct 3 10:04:20 2014 +0300

    Temp commit

commit 71781bf0a7807351a56d5155dac94169ea700527
Author: Olkun Mustafa <olkun.mustafa@gmail.com>
Date:   Fri Oct 3 10:01:42 2014 +0300

    First Commit

当我尝试重新设置此提交的基准时,出现如下错误

git rebase --interactive HEAD~2
fatal: Needed a single revision
invalid upstream HEAD~2

我在Google进行了相当的研究,但直到现在我都没有找到解决方案。


2
您尝试在这里实现什么结果?
奥利弗·查尔斯沃思

您是否要撤消提交?
mehmetseckin 2014年

Answers:


187

在您的情况下,没有HEAD~2,因为您只有2次提交,因此出现了Needed a single revision错误消息“ ”。
尝试:

 git rebase -i --root

在“ 使用Git更改项目的第一次提交? ”中查看更多内容。


1
谢谢!为我工作。
YuLong Xiao

1
即使我在日志中有四次提交,我也只能得到“致命的:无效的上游头〜2”。没有为我显示“单一修订”消息。但是,这使我正确起来!谢谢!
奥斯汀·霍根

7

这不适用于您的情况,但可能会帮助其他人。如果在Linux上,请确保HEAD大写。如果您head像下面的第一个示例那样使用小写字母(因为您习惯于在Windows或Mac上工作,并且允许小写字母head),则会收到fatal: Needed a single revision错误消息!

或者,您可以将它@用作的别名HEAD,则不必担心忘记大写。

# wrong on linux
git rebase --interactive head~2

# correct on linux
git rebase --interactive HEAD~2

# correct on all
git rebase --interactive @~2

非常感谢!我为此奋斗了几个小时,大写HEAD解决了!
Jinsong Li

1
⁺¹以获取有关的建议@
Hi-Angel
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.