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

Re: How to recover a lost commit...

From
SRSeth Robertson <in-gitvger@baka.org>
Date
Nov 11, 2010, 16:49 UTC
Message-ID
<201011111649.oABGnjca019731@no.baka.org>
In-Reply-To
<AANLkTinfYTMKicr3V=T=scVpOte_XrmaDgVA_oMj2fYU@mail.gmail.com>

In message <AANLkTinfYTMKicr3V=T=scVpOte_XrmaDgVA_oMj2fYU@mail.gmail.com>, 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.

Previous: Patrick DoyleNext: Patrick Doyle
Message 2 of 8 in “How to recover a lost commit...”
  1. Patrick DoyleNov 11, 2010
  2. Seth RobertsonNov 11, 2010
  3. Patrick DoyleNov 11, 2010
  4. Jonathan NiederNov 11, 2010
  5. Patrick DoyleNov 11, 2010
  6. Junio C HamanoNov 11, 2010
  7. Jonathan NiederNov 11, 2010
  8. Patrick DoyleNov 11, 2010

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.