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

Re: git reflog delete HEAD@{1} HEAD@{2} caught me by surprise...

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 14, 2012, 04:49 UTC
Message-ID
<7vlif91wv6.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20121013220855.24116.qmail@science.horizon.com>
"George Spelvin" <linux@horizon.com> writes:
Show 18 quoted lines
> Try the following commands in an empty directory:
> (I'm using the bash extention for {1..5}.)
>
> git init
> for i in {1..5}; do git commit -m "Commit $i" --allow-empty; done
> git reflog
> 	bc93e06 HEAD@{0}: commit: Commit 5
> 	e14f92d HEAD@{1}: commit: Commit 4
> 	ac64d8e HEAD@{2}: commit: Commit 3
> 	287602b HEAD@{3}: commit: Commit 2
> 	183a378 HEAD@{4}: commit (initial): Commit 1
> git reflog delete HEAD@{{1,2}}
> git reflog
> 	bc93e06 HEAD@{0}: commit: Commit 5
> 	e14f92d HEAD@{1}: commit: Commit 3
> 	287602b HEAD@{2}: commit (initial): Commit 1
>
> Er...I meant to delete Commit 3 from the reflog, not Commit 2.

Yeah, I've never tried to delete more than one with one command, but I am not surprised a naaïve implementation removes the first, and then removes the second in the resulting list.

Show 8 quoted lines
> To delete single entries from the reflog, use the subcommand "delete"
> and specify the _exact_ entry (e.g. "`git reflog delete master@{2}`").
>
> You may delete multiple reflog entries with one delete command,
> _however_ they are processed one at a time, so earlier deletes will cause
> renumbering that will affect later ones.  To delete reflog entries @{2}
> and @{3}, the command would be either "`git reflog delete @{3} @{2}`",
> or "`git reflog delete @{2} @{2}`".

I would actually call that behaviour a bug. Perhaps it should grab all the command line arguments first, group them per the ref the reflog entries are based on, and expire _all_ reflog entries from the same reflog in one go?

Until that happens, it may make sense to error it out when more than one entries are given from the command line, at least for the same ref.

Previous: George SpelvinNext: George Spelvin
Message 2 of 3 in “git reflog delete HEAD@{1} HEAD@{2} caught me by surprise...”
  1. George SpelvinOct 13, 2012
  2. Junio C HamanoOct 14, 2012
  3. George SpelvinOct 14, 2012

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.