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

Git

Git Problem Overview


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

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

Edit1:

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

Edit2:

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

Git Solutions


Solution 1 - Git

Several options:

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

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

  • try: git rebase -i --root

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

--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.`

Solution 2 - Git

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.

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionyikouniaoView Question on Stackoverflow
Solution 1 - GitCodeWizardView Answer on Stackoverflow
Solution 2 - GitDavid SiegalView Answer on Stackoverflow