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

Re: Git Rebase Issue

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 22, 2015, 19:25 UTC
Message-ID
<xmqqwps6cmkf.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<39E7EE9D306F544FAD3A0D16B7B7CAAD2C1E819D@mtlsvrmxwv02.A2M.com>
Pierre-Luc Loyer <Pierre-Luc.Loyer@bhvr.com> writes:
> 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>

You do not have to say "HEAD" for "<branch>", if you are rebasing the current branch. Either leave it unsaid, or name the branch.

Passing "HEAD" (or any of its variants that names the exact commit at the tip of the current branch, without using the name of the current branch, e.g. "master^0") as the "branch to rebase" is an advanced technique to use when you want to avoid messing with the branch itself. It is deliberate that the HEAD is left detached.

You'd (once you learn Git sufficently and got comfortable with working on a detached HEAD, that is) often find yourself doing things like this:

1. rebase temporarily on detached HEAD
    $ git rebase -i HEAD~2 HEAD ;# amend the tip two
2. double check the result and convince yourself that it is better
   than the original
    $ git diff master HEAD
    $ git log master.. >updated
    $ git log -2 master >original
    $ diff -u original updated
3-a. once satisfied, update the branch
    $ git checkout -B master
3-b. or abandon if the result is undesirable.
    $ git checkout master
Previous: Pierre-Luc LoyerNext: Christian Couder
Message 2 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.