threads / bug / 11955

Bug in git rebase -i where <upstream> is "HEAD" in 1.5.4?

Subject: Bug in git rebase -i where <upstream> is "HEAD" in 1.5.4?

## tl;dr

2 messages between Feb 7, 2008 and Feb 7, 2008.

replies: 1people: 2as markdown or json

Adam Roben· Feb 7, 2008, 21:47 UTC · lore
Hi all-
    I've discovered a difference in behavior between `git rebase` and  
`git rebase -i`, and I believe the behavior exhibited by `git rebase - 
i` is incorrect and should be changed to match `git rebase`. The  
behavior difference occurs when running the command in the form:
git rebase [-i] <upstream> <branch>
    If <upstream> is "HEAD", `git rebase` seems to perform these  
(correct) steps:

A=$(git rev-parse HEAD) git checkout <branch> git rebase $A

    However, `git rebase -i` seems to perform these (incorrect) steps:

git checkout <branch> git rebase -i HEAD

    The problem is that `git checkout` changes the meaning of HEAD  
(naturally), and so these steps are not equivalent. The end result is  
that `git rebase -i HEAD <branch>` just checks out <branch> and prints  
"Nothing to do", while when -i is omitted the rebase occurs as  
expected. Below is a transcript that shows exactly what I mean.
-Adam
% git init
Initialized empty Git repository in .git/
% touch onmaster
% git add onmaster
% git commit -m "Added onmaster"
Created initial commit 7c3e0f1: Added onmaster
  0 files changed, 0 insertions(+), 0 deletions(-)
  create mode 100644 onmaster
% touch onmaster2
% git add onmaster2
% git commit -m "Added onmaster2"
Created commit c19019b: Added onmaster2
  0 files changed, 0 insertions(+), 0 deletions(-)
  create mode 100644 onmaster2
% git checkout -b work HEAD^
Switched to a new branch "work"
% touch onwork
% git add onwork
% git commit -m "Added onwork"
Created commit ae14495: Added onwork
  0 files changed, 0 insertions(+), 0 deletions(-)
  create mode 100644 onwork
% touch onwork2
% git add onwork2
% git commit -m "Added onwork2"
Created commit 64b3dc0: Added onwork2
  0 files changed, 0 insertions(+), 0 deletions(-)
  create mode 100644 onwork2
% ls
onmaster onwork   onwork2
% git checkout master
Switched to branch "master"
% ls
onmaster  onmaster2
% git rebase -i HEAD work
Nothing to do
% ls
onmaster onwork   onwork2
Junio C Hamano· Feb 7, 2008, 23:32 UTC · re: Adam Roben · lore

Re: Bug in git rebase -i where <upstream> is "HEAD" in 1.5.4?

Adam Roben <aroben@apple.com> writes:
Show 13 quoted lines
>    I've discovered a difference in behavior between `git rebase` and
> `git rebase -i`, and I believe the behavior exhibited by `git rebase -
> i` is incorrect and should be changed to match `git rebase`. The
> behavior difference occurs when running the command in the form:
>
> git rebase [-i] <upstream> <branch>
>
>    If <upstream> is "HEAD", `git rebase` seems to perform these
> (correct) steps:
>
> A=$(git rev-parse HEAD)
> git checkout <branch>
> git rebase $A

Yes, I remember writing that side carefully, taking exactly this issue into account.

>    However, `git rebase -i` seems to perform these (incorrect) steps:

Yeah, I see that interactive side is sloppier. In git-rebase--interactive.sh, if you move

        HEAD=$(git rev-parse --verify HEAD) || die "No HEAD?"
        UPSTREAM=$(git rev-parse --verify "$1") || die "Invalid base"

around l.481 up so that they come before if test ! -z "$2", you would be Ok, although I didn't test it.

← back to recent threads