From: Chris Shoemaker <c.shoemaker@cox.net>
To: Jakub Narebski <jnareb@gmail.com>
Cc: geoffrey.russell@gmail.com, git@vger.kernel.org
Subject: Re: About detached heads
Date: Fri, 14 Mar 2008 09:42:05 -0400 [thread overview]
Message-ID: <20080314134205.GA19674@pe.Belkin> (raw)
In-Reply-To: <m3lk4ly3vy.fsf@localhost.localdomain>
On Fri, Mar 14, 2008 at 03:52:14AM -0700, Jakub Narebski wrote:
> "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.
[Great explanation. Let me offer one minor clarification:]
This way you would get exactly:
1---2---3---4---5---3' <--- master <--- HEAD
While the 3' commit has the same contents as 3, it is a new, distinct
commit with its own history. Its commit message should explain why
you want to go from 5 back to the contents of 3.
-chris
next prev parent reply other threads:[~2008-03-14 14:40 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
2008-03-14 12:16 ` Sergei Organov
2008-03-14 12:28 ` Adam Piatyszek
2008-03-14 13:42 ` Chris Shoemaker [this message]
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=20080314134205.GA19674@pe.Belkin \
--to=c.shoemaker@cox.net \
--cc=geoffrey.russell@gmail.com \
--cc=git@vger.kernel.org \
--cc=jnareb@gmail.com \
/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.