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

ambiguous git-reflog output for symbolic refs

From
Chris Jerdonek <chris.jerdonek@gmail.com>
Date
Feb 29, 2020, 04:49 UTC
Message-ID
<CAOTb1wfXp+gXSwbG-CVgVE8E_5yzxQKwNKh_=3ECqTMvZFw7dQ@mail.gmail.com>
Hi,

I encountered some output that seems unexpected and ambiguous to me when calling git-reflog on a symbolic ref.

Specifically, if the symbolic ref has no reflog of its own, then git-reflog shows the reflog of the symbolic ref's target, but with the symbolic ref's name in the output lines. This means you can't tell if the reflog entries are from the symbolic ref's reflog, or from the symbolic ref target's reflog:

To illustrate, create a symbolic ref pointing to a branch (this is using git version 2.25.0):

$ git update-ref -m AAA refs/heads/test-branch 931dd4e7f267865e8077ae47c75888fe5d1b2755 $ git symbolic-ref refs/my-symbolic refs/heads/test-branch

Now, the git-reflog command below shows the log entries for refs/heads/test-branch:

$ git reflog refs/my-symbolic 931dd4e (HEAD -> master, refs/my-symbolic, test-branch) refs/my-symbolic@{0}: AAA

But if we ensure that refs/my-symbolic has its own reflog, e.g. by doing this:

$ git update-ref -m BBB --create-reflog refs/my-symbolic 931dd4e7f267865e8077ae47c75888fe5d1b2755

Then running the same git-reflog command as above now shows the symbolic ref's reflog instead of the target's:

$ git reflog refs/my-symbolic 931dd4e (HEAD -> master, refs/my-symbolic, test-branch) refs/my-symbolic@{0}: BBB

(The ref is still a symbolic ref pointing to "test-branch" as you can see below.)

$ git symbolic-ref refs/my-symbolic refs/heads/test-branch

To recap, looking at the two git-reflog outputs above, there's no way to tell from the output which of the two cases you're in (the symbolic ref's reflog or the target's).

So my question is: Is this behaving like it should? I was surprised that git-reflog dereferences the symbolic ref prior to querying the reflog, and even more surprising, replaces "refs/heads/test-branch" in refs/heads/test-branch's reflog with "refs/my-symbolic".

And either way, is there a way to get unambiguous output? For example, is there a way to make sure you're reading the symbolic ref's reflog and not the reflog of its target?

Thank you, --Chris

Message 1 of 1 in “ambiguous git-reflog output for symbolic refs”
  1. Chris JerdonekFeb 29, 2020

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.