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

Re: accessing oldest reflog entry with ref@{N}?

From
Jeff King <peff@peff.net>
Date
Jun 19, 2013, 19:41 UTC
Message-ID
<20130619194116.GB25160@sigill.intra.peff.net>
In-Reply-To
<7vk3lqym1q.fsf@alter.siamese.dyndns.org>
On Wed, Jun 19, 2013 at 11:48:01AM -0700, Junio C Hamano wrote:
Show 20 quoted lines
> SZEDER Gábor <szeder@ira.uka.de> writes:
> 
> > $ git log --oneline -1 master@{1}
> > fatal: Log for 'master' only has 1 entries.
> >
> > Annoyed, I just copy-pasted the sha and got the job done.
> >
> > However, I wonder why it didn't worked. 'git reflog' didn't print
> > master@{1} or any message for the oldest entry, but I can live without
> > that.
> 
> There lies your answer, no?
> 
> Each of the log entry records "this was before, and this is after
> the change".  ref@{0} reads from the "after" field of 0-th (from the
> end) entry. ref@{1} reads from the "after" field of 1-st (again from
> the end) entry.  ref@{N} reads from the "after" field of N-th (again
> from the end) entry.
> 
> Notice that nowhere in the above sequence we read from "before" field.

In general, the "before" from entry @{N} should be the same as the "after" of @{N+1}. Of course this is not always the case for various reasons, the most common of which I think are:

  1. Buggy scripts which do not provide a reflog reason for their call
     to git-update-ref, and therefore update the ref without writing a
     reflog entry.
  2. A git-gc will expire entries which point to unreachable objects
     much earlier, which can create "holes" in the reflog.

So it is certainly not correct to say "we do not have a master@{1} entry, but we know that the 'before' entry of master@{0} must point to the same thing". But it is very often a good guess. I wonder if there should be some simple way to expose that value as an @{}-selector. Perhaps "ref@{0.before}" or something?

-Peff
Previous: Junio C Hamano
Message 3 of 3 in “accessing oldest reflog entry with ref@{N}?”
  1. SZEDER GáborJun 19, 2013
  2. Junio C HamanoJun 19, 2013
  3. Jeff KingJun 19, 2013

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.