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

Re: undoing something

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 16, 2009, 19:14 UTC
Message-ID
<7veiwxwa9z.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<450196A1AAAE4B42A00A8B27A59278E70A2AEFA4@EXCHANGE.trad.tradestation.com>
"John Dlugosz" <JDlugosz@TradeStation.com> writes:
Show 12 quoted lines
> I made a mistake.  Big deal, now that I know that git storage is
> immutable and changes just add to what's already there.  
>
> A quick look at
> 	git reflog show topic
> tells me that {1} is the one I want.  So, how do I rewind branch topic
> to point to topic@{1} ?
> I did it by making a tag, and then in gitk pointing to it and picking
> "reset to here" from the context menu.  
>
> A while back I was looking for the right/easy way to simply repoint my
> branch to where I wanted.  The best answer was to use push.

The answer was best only because in your previous question you wanted to ensure fast-forwardness, i.e. "git push . origin/dev:dev" without plus in front to cause it to fail if it is not fast-forward.

If you know you have one unwanted commit you would want to discard at the tip of topic, you do not want fast-foward safety to kick in.

 (1) if you are on the topic branch, you can say "git reset --hard HEAD^";
     or
 (2) if you are not, you can obviously check out topic and do the above,
     or "git branch -f topic topic^".

If the garbage you have at the tip of the topic is not just a single commit, you can replace HEAD^ and topic^ in the above with whatever commit you would want to point the tip at.

Previous: John DlugoszNext: John Dlugosz
Message 2 of 15 in “undoing something”
  1. John DlugoszMar 16, 2009
  2. Junio C HamanoMar 16, 2009
  3. John DlugoszMar 16, 2009
  4. Junio C HamanoMar 16, 2009
  5. Effective PostingJohn Dlugosz, Mar 16, 2009
  6. René ScharfeMar 16, 2009
  7. John DlugoszMar 16, 2009
  8. Jay SoffianMar 16, 2009
  9. John DlugoszMar 16, 2009
  10. (unknown)Nanako Shiraishi, Mar 16, 2009
  11. Junio C HamanoMar 17, 2009
  12. git-branch.txt: document -f correctlyMichael J Gruber, Mar 17, 2009
  13. Junio C HamanoMar 17, 2009
  14. Michael J GruberMar 17, 2009
  15. John DlugoszMar 17, 2009

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.