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

Re: Cancelling certain commits

From
Junio C Hamano <junkio@cox.net>
Date
Jan 16, 2006, 23:43 UTC
Message-ID
<7vvewjlowk.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<43CBAC0B.3020104@op5.se>
Andreas Ericsson <ae@op5.se> writes:
 ... (all the good stuff not repeated).

As a general rule, first of all, make sure that this kind of "cleaning up the history" can be done only before you make your history available to others, and not after.

Show 8 quoted lines
> # make sure "git status" doesn't show any changes
>
> $ git branch anchor # to make a safe point to reset to if things go bad
> $ git reset --hard HEAD~7 # undo commits 3 - 10
> # replay commits 4, 5, 6, 8, 9
> $ for i in 6 5 4 2 1; do git cherry-pick -r anchor~$i || break; done
> # replay commit 10
> $ git cherry-pick -r anchor
I think "6 5 4 2 1 0" would be sweeter.  rev~0 == rev
Show 8 quoted lines
> ..., and never *ever*
> do
>
> $ git prune
>
> on a repo where you're juggling loose commits like this (although that
> should actually be safe when you create 'anchor' as a branch rather
> than as a tag, which Junio usually recommends).

Sorry, I do not understand this part. tags and branch heads are used in the same way to determine what objects to protect from "prune", so I thought there was no difference from the safety point of view between the anchor being a branch or a tag.

Previous: Andreas EricssonNext: Andreas Ericsson
Message 3 of 4 in “Cancelling certain commits”
  1. Bahadir BalbanJan 16, 2006
  2. Andreas EricssonJan 16, 2006
  3. Junio C HamanoJan 16, 2006
  4. Andreas EricssonJan 17, 2006

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.