All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jakub Narebski <jnareb@gmail.com>
To: geoffrey.russell@gmail.com
Cc: git@vger.kernel.org
Subject: Re: About detached heads
Date: Fri, 14 Mar 2008 03:52:14 -0700 (PDT)	[thread overview]
Message-ID: <m3lk4ly3vy.fsf@localhost.localdomain> (raw)
In-Reply-To: <93c3eada0803140246k53408c74m21f9dc277857202d@mail.gmail.com>

"Geoff Russell" <geoffrey.russell@gmail.com> writes:

> This should be simple! I have a series of commits:
> 
>            1---2---3---4---5
> 
> I want to go back to 3 but not branch, so I want
> 
>            1---2---3---4---5---3
> 
> ?
> 
>          git checkout 3...
> 
> gets me the commit on a detached head, but I don't know how to put this back
> as the HEAD.

Lets check what git does in each of scenarios. Let's assume that
current branch is named 'master'.

At beginning we have:

   1---2---3---4---5    <--- master <--- HEAD

HEAD contents is "ref: refs/heads/master"

1. Now, "git checkout 3...", which is equivalent to "git checkout 3",
detaches HEAD because commit '3' is not a head (is not a branch), so
we have:

   1---2---3---4---5    <--- master
           ^
            \ 
             \-------------- HEAD

HEAD contents is "<sha1 of 3>"


2. If we did "git reset --hard 3" we would rewind the history,
resulting in the following situation:

   1---2---3           <--- master <--- HEAD
            \           
             \-4---5   <... master@{1}, ORIG_HEAD, HEAD@{1}
              
and now commits 4 and 5 are referenced only by reflogs, and by the
(temporary) "last position of HEAD" reference named ORIG_HEAD.


3. Now, if you have published 1..5 history you would not want
(usually) to rewind published branch. If you do the following:

  $ git revert --no-commit 5
  $ git revert 4

you would get the following:

   1---2---3---4---5---(5^-1 4^-1 => 3)  <--- master <--- HEAD

git-revert applies reversal of changes in given commit, in the 
"patch -R" ("patch --reverse") sense. Using '--no-commit' option
allows to squash reverting two commits into one commit. The ordering
of reverting ensures that there are no merge conflicts.


4. Or you can just put the _contents_ of revision 3 into your working
tree, either using plumbing command git-read-tree, or by checking out
or resetting to top tree: "git checkout 3^{tree}", or 
"git checkout 3 -- .", or equivalent git-reset invocation.

This way you would get exactly

   1---2---3---4---5---3   <--- master <--- HEAD

but the relation of 5---3 parentage is unclear: you would have to
explain it in the commit mesage.

HTH
-- 
Jakub Narebski
Poland
ShadeHawk on #git

  parent reply	other threads:[~2008-03-14 10:52 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-14  9:46 About detached heads Geoff Russell
2008-03-14  9:51 ` Jonathan del Strother
2008-03-14 10:39   ` David Kågedal
2008-03-14 10:15 ` Wincent Colaiuta
2008-03-14 10:48   ` Matthieu Moy
2008-03-14 11:17     ` Wincent Colaiuta
2008-03-14 10:52 ` Jakub Narebski [this message]
2008-03-14 12:16   ` Sergei Organov
2008-03-14 12:28   ` Adam Piatyszek
2008-03-14 13:42   ` Chris Shoemaker
2008-03-14 14:53     ` Rafael Garcia-Suarez
2008-03-14 15:19       ` Nicolas Pitre
2008-03-14 15:21       ` Jakub Narebski
2008-03-14 17:53 ` Linus Torvalds
2008-03-14 18:37   ` Björn Steinbrink
2008-03-14 18:51     ` Linus Torvalds
2008-03-14 19:11       ` Jakub Narebski
2008-03-14 19:17         ` Sean
2008-03-14 23:43           ` Geoff Russell
2008-03-15  0:03             ` Jakub Narebski
2008-03-15  0:38             ` Nicolas Pitre
2008-03-15  2:03               ` Geoff Russell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3lk4ly3vy.fsf@localhost.localdomain \
    --to=jnareb@gmail.com \
    --cc=geoffrey.russell@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.