git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Git Rebase Issue

From
Christian Couder <christian.couder@gmail.com>
Date
Dec 22, 2015, 21:02 UTC
Message-ID
<CAP8UFD3F6+VRyEF6XuxUcC_qiY7k4a-g8J-NKBZWDk=1=m1=WA@mail.gmail.com>
In-Reply-To
<39E7EE9D306F544FAD3A0D16B7B7CAAD2C1E819D@mtlsvrmxwv02.A2M.com>
Hi,

On Tue, Dec 22, 2015 at 6:53 PM, Pierre-Luc Loyer <Pierre-Luc.Loyer@bhvr.com> wrote:

Show 39 quoted lines
> Hi,
>
> I've encountered a situation using rebase for which I don't understand the results, even after reading the documentation.
> I'm currently working in my feature branch and then I want to squash commits, thus I use interactive rebase. After successfully completing the rebase, I end up in a detached HEAD state, rather than back on my branch, which is confusing. The command that is causing me to be in detached HEAD mode is: git rebase -i HEAD~2 HEAD
> From the documentation, I read that my second parameter (HEAD) is the <branch> parameter:
>
>    git rebase [-i | --interactive] [options] [--exec <cmd>] [--onto <newbase>]
>
>    [<upstream>] [<branch>]
>
>    If <branch> is specified, git rebase will perform an automatic git checkout <branch> before doing anything else. Otherwise it remains on the current branch.
> <branch> Working branch; defaults to HEAD.
>
>    Upon completion, <branch> will be the current branch.
>
> Here is a full example than can be used to easily repro the issue. Go to an empty folder.
> git init
> git echo text > file.txt
> git add .
> git commit -m "Add file.txt"
> git echo text2 > file.txt
> git commit -am "Modify file.txt"
> git echo text3 > file.txt
> git commit -am "Remodify file.txt"
>
> Now the interesting part:
> $ git rebase -i HEAD~2 HEAD
> [detached HEAD 9178b93] Modify file
> 1 file changed, 1 insertion(+), 1 deletion(-)
> Successfully rebased and updated detached HEAD.
>
> From the documentation it says that <branch> (which is HEAD) will be checked out before doing anything and that upon completion, <branch> will be the current branch. However, this doesn't seem to happen. In fact, it seems more like the following is happening during the rebase:
> 1) detach HEAD
> 2) rebase
> 3) reattach to <branch>
>
> If <branch> is HEAD, then is does nothing and remains detached.
> I find this behavior confusing since I would expect it to return to whatever HEAD was pointing to at the start of the command, such as my branch. Also, the documentation says that the <branch> parameter defaults to HEAD, so passing 'HEAD' explicitly should result in the same behavior as not passing it:
> <branch> Working branch; defaults to HEAD.

You are right, it is probably a bug. I guess usually people just use "git rebase -i HEAD~2" or "git rebase -i master" and don't give the [<branch>] argument when using -i.

If you are interested in helping us debug this you might first want to check if older git versions behaved like this.

Thanks, Christian.

Previous: Junio C Hamano
Message 3 of 3 in “Git Rebase Issue”
  1. Pierre-Luc LoyerDec 22, 2015
  2. Junio C HamanoDec 22, 2015
  3. Christian CouderDec 22, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.