Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

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.

like image 422
yikouniao Avatar asked Nov 25 '15 08:11

yikouniao


People also ask

What is git rebase -- root?

Git has a built in way to rebase all the way back to the beginning of time. There is no need to scroll through the log to find the first hash, or find the total number of commits. Just use --root .


2 Answers

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.` 
like image 189
CodeWizard Avatar answered Sep 20 '22 13:09

CodeWizard


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.

like image 32
David Siegal Avatar answered Sep 19 '22 13:09

David Siegal