git rebase 致命:需要一个无效的上游修订版 –i

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33911379/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 03:43:33  来源:igfitidea点击:

git rebase fatal: Needed a single revision invalid upstream –i

git

提问by yikouniao

I am trying to squanshing several commits together. When I used

我正在尝试将多个提交压缩在一起。当我使用

git rebase –i HEAD~8

I got a fatal:

我有一个致命的:

fatal: Needed a single revision
invalid upstream –i

Here is a part of commit logs: git log

这是提交日志的一部分: git log

All of the commits history of the corresponding Github repository is here: https://github.com/yikouniao/YukiLog/commits/master

相应的 Github 存储库的所有提交历史都在这里:https: //github.com/yikounio/YukiLog/commits/master

Edit1:

编辑1:

When I used git rebase –i HEAD~2, I got the same result.

当我使用 git 时rebase –i HEAD~2,我得到了相同的结果。

Edit2:

编辑2:

I didn't know I had modified the file.gitconfig, editor = notepad2was add to the file. After I removed editor = notepad2, everything is OK. Then I rebased and squanshed 8 commits successfully.

我不知道我修改了文件.gitconfigeditor = notepad2被添加到文件中。我删除后editor = notepad2,一切正常。然后我重新定位并成功消除了 8 个提交。

回答by CodeWizard

Several options:

几个选项:

  • You are not on a branch (Detached head) or maybe you are trying to rebaseor the wrong branch.
    Checkout the branch you want to rebaseand try again.

  • you don't have 8 commits in your history (you have 7 or less)

  • try: git rebase -i --root

  • 您不在分支 ( Detached head) 上,或者您正在尝试rebase或错误的分支。
    签出您想要的分支并重rebase试。

  • 您的历史记录中没有 8 次提交(您有 7 次或更少)

  • 尝试: git rebase -i --root

Here is the documentation for the --rootflag and why it will work for you.

这是该--root标志的文档以及它为什么对您有用。

--root

- 根

Rebase all commits reachable from <branch>, instead of limiting them with
an <upstream>.This allows you to rebase the root commit(s) on a branch.  
When used with --onto, it will skip changes already contained in `<newbase>`   
(instead of `<upstream>`) whereas without --onto it will operate on every 
change. When used together with both --onto and --preserve-merges, all root 
commits will be rewritten to have `<newbase>` as parent instead.`

回答by David Siegal

The problem is the dash in your –i. It's an en-dash (U2013) instead of a hyphen (U002D). I confirmed this by copying your dash and looking it up at http://unicode.scarfboy.com. Change it to -i instead.

问题是您的 –i 中的破折号。它是一个短划线 (U2013) 而不是连字符 (U002D)。我通过复制您的破折号并在http://unicode.scarfboy.com 上查找来确认这一点。改为 -i 。

The clue was the error message "invalid upstream –i". Git didn't recognize your –i as a flag and was instead interpreting it as the upstream parameter.

线索是错误消息“上游无效 -i”。Git 没有将您的 –i 识别为标志,而是将其解释为上游参数。