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

Re: How to recover a lost commit...

From
PDPatrick Doyle <wpdster@gmail.com>
Date
Nov 11, 2010, 18:19 UTC
Message-ID
<AANLkTik_zW1ih=wF-dWTjsFhToNy1fOxy0XJXT1i1RTo@mail.gmail.com>
In-Reply-To
<20101111175836.GD16972@burratino>
On Thu, Nov 11, 2010 at 12:58 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:
> Right.  In general, git operations that update HEAD also tend to take
> the current branch along with them.

Ahhhh.... that's the missing piece, errr, one of the missing pieces, to my puzzled brain.

So
$ git reset HEAD

updates HEAD (and whatever branch we are currently on) to point to HEAD. Except for mucking with the index, that seems pretty benign.

$ git reset HEAD^

updates HEAD (and whatever branch we are currently on) to point to HEAD^, thus backing everything up by 1 commit. As you pointed out, this is dangerous/not a good idea/ if I've already pushed my repository someplace.

In my particular case, after doing the "git reset HEAD^" on my svn_to_git_wip branch, I later tried to switch back to master ("git checkout master"). Git warned me about files that were not up to date and refused to merge (but I thought I was checking out, not merging). Since I knew what I was doing (we all know how sadly lacking in truth that statement is now, don't we), I "git reset --hard" those files (thus discarding my changes) and proceeded to check out master.

Light dawns on marble head.
Thanks again.
--wpd
Previous: Jonathan NiederNext: Junio C Hamano
Message 5 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.