threads / discuss / 55043

Can not rebase to first commit

Subject: Can not rebase to first commit

## tl;dr

7 messages between Jan 25, 2021 and Jan 26, 2021.

replies: 6people: 6as markdown or json

Eugen Konkov· Jan 25, 2021, 10:38 UTC · lore
I can not rebase to first commit.
This is how to reproduce:
kes@work ~/work/projects/general/Auth $ git tree
* 67857d5 (HEAD -> dev) asdf
* 1e99034 (local/dev) Initial commit
kes@work ~/work/projects/general/Auth $ git rebase -i --autostash --rebase-merges 1e99034^
fatal: invalid upstream '1e99034^'

git --version git version 2.30.0

-- Best regards, Eugen Konkov

Matheus Tavares Bernardino· Jan 25, 2021, 16:53 UTC · re: Eugen Konkov · lore

Re: Can not rebase to first commit

Hi, Eugen
On Mon, Jan 25, 2021 at 7:50 AM Eugen Konkov <kes-kes@yandex.ru> wrote:
Show 10 quoted lines
>
> I can not rebase to first commit.
>
> This is how to reproduce:
>
> kes@work ~/work/projects/general/Auth $ git tree
> * 67857d5 (HEAD -> dev) asdf
> * 1e99034 (local/dev) Initial commit
> kes@work ~/work/projects/general/Auth $ git rebase -i --autostash --rebase-merges 1e99034^
> fatal: invalid upstream '1e99034^'

'1e99034^' means "the first parent of 1e99034". However, this is the root commit of your branch, so it has no parent. That's why rebase complained about '1e99034^' being invalid. To rebase this commit you can instead use the --root option.

Thanks, Matheus

Taylor Blau· Jan 25, 2021, 14:21 UTC · re: Eugen Konkov · lore

Re: Can not rebase to first commit

On Mon, Jan 25, 2021 at 12:38:16PM +0200, Eugen Konkov wrote:
Show 7 quoted lines
> I can not rebase to first commit.
>
> This is how to reproduce:
>
> kes@work ~/work/projects/general/Auth $ git tree
> * 67857d5 (HEAD -> dev) asdf
> * 1e99034 (local/dev) Initial commit

(Unrelated to your question, but I assume that 'git tree' is an alias of 'git log --oneline --graph' by the looks of it).

> kes@work ~/work/projects/general/Auth $ git rebase -i --autostash --rebase-merges 1e99034^
> fatal: invalid upstream '1e99034^'

Yes, this is because you're asking to rebase your branch onto the parent of 1e99034, which doesn't exist because 1e99034 is the "root" commit and therefore has no parents.

'git rebase' has a special option for exactly this case, which is '--root'. By replacing '1e99034^' with '--root', you should be able to do what you want.

Thanks, Taylor

Thomas Braun· Jan 25, 2021, 13:24 UTC · re: Eugen Konkov · lore

Re: Can not rebase to first commit

On 1/25/2021 11:38 AM, Eugen Konkov wrote:
Show 9 quoted lines
> I can not rebase to first commit.
> 
> This is how to reproduce:
> 
> kes@work ~/work/projects/general/Auth $ git tree
> * 67857d5 (HEAD -> dev) asdf
> * 1e99034 (local/dev) Initial commit
> kes@work ~/work/projects/general/Auth $ git rebase -i --autostash --rebase-merges 1e99034^
> fatal: invalid upstream '1e99034^'

See `git rebase --root` where the documentation says "This allows you to rebase the root commit(s) on a branch.".

Martin Ågren· Jan 25, 2021, 11:30 UTC · re: Eugen Konkov · lore

Re: Can not rebase to first commit

On Mon, 25 Jan 2021 at 11:53, Eugen Konkov <kes-kes@yandex.ru> wrote:
Show 10 quoted lines
>
> I can not rebase to first commit.
>
> This is how to reproduce:
>
> kes@work ~/work/projects/general/Auth $ git tree
> * 67857d5 (HEAD -> dev) asdf
> * 1e99034 (local/dev) Initial commit
> kes@work ~/work/projects/general/Auth $ git rebase -i --autostash --rebase-merges 1e99034^
> fatal: invalid upstream '1e99034^'
The commit 1e99034 has no parent, so 1e99034^ errors out.
Try the `--root` option. That should do what you want.
Martin
Kevin Daudt· Jan 25, 2021, 11:22 UTC · re: Eugen Konkov · lore

Re: Can not rebase to first commit

On Mon, Jan 25, 2021 at 12:38:16PM +0200, Eugen Konkov wrote:
Show 18 quoted lines
> I can not rebase to first commit.
> 
> This is how to reproduce:
> 
> kes@work ~/work/projects/general/Auth $ git tree
> * 67857d5 (HEAD -> dev) asdf
> * 1e99034 (local/dev) Initial commit
> kes@work ~/work/projects/general/Auth $ git rebase -i --autostash --rebase-merges 1e99034^
> fatal: invalid upstream '1e99034^'
> 
> 
> git --version
> git version 2.30.0
> 
> --
> Best regards,
> Eugen Konkov 
> 

This is because the first commit (1e99034) does not have a parent, so 1e99034^ cannot be resolved.

git rebase does however have an option for this: git rebase -i --root. That allows you to rebase the root commit.

Hope this helps, Kevin

← back to recent threads