Re: How to recover a lost commit...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In message <AANLkTinfYTMKicr3V=T=scVpOte_XrmaDgVA_oMj2fYU@xxxxxxxxxxxxxx>, Patr
ick Doyle writes:

    I've just noticed however, that my work in progress, no longer seems
    to be there, and I'm at a loss to understand why it disappeared.  I've
    tried various checkouts to get it back (the commit containing it was
    286f167).

    But I'm curious... given the reflog show below... can any of you tell
    what I did to myself to shoot myself in the foot?  Aside from "use git
    stash next time dummy", is there any way I could have avoided this?

No problem.  We deal with stuff like this on #git in IRC all of the time.

    $ git reflog
    ce11719... HEAD@{0}: checkout: moving from master to svn_to_git_wip
    40070a1... HEAD@{1}: checkout: moving from svn_to_git_wip to master
    ce11719... HEAD@{2}: ce11719: updating HEAD
    286f167... HEAD@{3}: 286f167: updating HEAD
    d8c9d02... HEAD@{4}: checkout: moving from master to svn_to_git_wip

HEAD@{3} shows that your commit of interest was the head of
svn_to_git_wip.  HEAD@{2} shows that this was changed to whatever
ce11719 points to (apparently the commit before the commit of interest).

"Updating HEAD" is often a sign of running `git reset`

What you probably want to do is:

git checkout svn_to_git_wip
git reset --hard 2867167 (or HEAD@{3} <- caution, number may have changed)
git checkout master
git merge svn_to_git_wip

You could do a three-argument rebase instead of a merge, but merge is
much simpler.

					-Seth Robertson


----------------------------------------------------------------------
286f167... HEAD@{6}: checkout: moving from master to 286f167

Checking out the SHA directly--disconnected head.  Nothing wrong with
that per-se, but probably not where you want to go.

ce11719... HEAD@{14}: rebase: updating HEAD
3638aa3... HEAD@{15}: checkout: moving from svn_to_git_wip to
3638aa3f6e8496b5415ab59bec2a7af07b8ed169

rebasing a disconnected head is definitely not where you want to go.
You should not in general make modifications if you are not on a branch

cb98d3f... HEAD@{26}: checkout: moving from svn_to_git_wip to master
ce11719... HEAD@{27}: HEAD^: updating HEAD
286f167... HEAD@{31}: commit: Saving WIP at the time I switched from SVN to GIT
ce11719... HEAD@{32}: checkout: moving from master to svn_to_git_wip

HEAD@{27} was your original problem.  You made the commit on @{32}
then for some reason did (probably) a `git reset HEAD^` That was the
source of all of your problems.  You should only use `git reset` if
you have not pushed and if you are very sure you want to get rid of a
commit or changes.  It is a powerful command and with great power
comes great responsibility.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]