All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>
To: Martin Fick <mfick@codeaurora.org>
Cc: "SZEDER Gábor" <szeder@ira.uka.de>,
	"Daly Gutierrez" <daly.gutierrez@gmail.com>,
	git@vger.kernel.org
Subject: Re: Recovering Committed Changes in a Detached Head?
Date: Sun, 09 Oct 2011 10:12:22 +0200	[thread overview]
Message-ID: <vpqvcry4m8p.fsf@bauges.imag.fr> (raw)
In-Reply-To: <ab706826-75df-4410-941e-6b40ec92713c@email.android.com> (Martin Fick's message of "Sat, 08 Oct 2011 16:00:33 -0600")

Martin Fick <mfick@codeaurora.org> writes:

>>git reflog to the rescue.  For your example above it will output
>>something like this:
>>
>>deadbeef HEAD@{0}: checkout: moving from
>>92aa5381b9f7229523dba42aa94735c30f173451 to New_Branch
>>  92aa5381 HEAD@{1}: commit: Committing this in the Detached Head
>>3a5bb38a HEAD@{2}: checkout: moving from master to
>>3a5bb38a83c00f7acab573f0ec836577143200aa
>>  deafbabe HEAD@{3}: ...
>>  ...
>>
>>There you see the first line of the commit message from your "lost"
>>commit, and you can do
>>
>>  git checkout -b lost_detached_head 92aa5381
>>
>>and you get a branch pointing to that commit you made while on
>>detached head, and you can work with it as usual.
>
> While rflog is cool, I can't help but think that git could be even more helpful for these scenarios.

Git has been showing a big scary warning when entering detached HEAD,
and now has another helpful one when leaving a commit orphan:

$ git checkout HEAD^
Note: checking out 'HEAD^'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b new_branch_name

HEAD is now at adcbd2f... foo

$ date > foo.txt; git add foo.txt; git commit -am "commited on detached HEAD"
[detached HEAD 9e9c4ef] commited on detached HEAD
 1 files changed, 1 insertions(+), 1 deletions(-)

$ git checkout master
Warning: you are leaving 1 commit behind, not connected to
any of your branches:

  9e9c4ef commited on detached HEAD

If you want to keep them by creating a new branch, this may be a good time
to do so with:

 git branch new_branch_name 9e9c4efeca049ca559541595c9ca4a3380dee523

Switched to branch 'master'

(since 8e2dc6ac06ae90, Junio C Hamano, Fri Feb 18 16:04:47 2011, commit:
give final warning when reattaching HEAD to leave commits behind)

I think these warnings are (scary and big) enough.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

  parent reply	other threads:[~2011-10-09  8:12 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-08 20:58 Recovering Committed Changes in a Detached Head? Daly Gutierrez
2011-10-08 21:37 ` SZEDER Gábor
2011-10-08 22:00   ` Martin Fick
2011-10-09  3:32     ` Joel C. Salomon
2011-10-09  5:39       ` Martin Fick
2011-10-09  5:52     ` Nguyen Thai Ngoc Duy
2011-10-09  7:46       ` Ronan Keryell
2011-10-09  8:12     ` Matthieu Moy [this message]
2011-10-09 23:22     ` Junio C Hamano
2011-10-10  1:26       ` Miles Bader

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=vpqvcry4m8p.fsf@bauges.imag.fr \
    --to=matthieu.moy@grenoble-inp.fr \
    --cc=daly.gutierrez@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=mfick@codeaurora.org \
    --cc=szeder@ira.uka.de \
    /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.