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

reftable: wrong HEAD reflog when its target is updated in the same transaction

From
井井上司 <inoue.tsukasa.4@gmail.com>
Date
Nov 8, 2026, 12:50 UTC
Message-ID
<CAP8tz2L3Dfhd+ec4+SFkZgXmzQnBg+3Y0REAV+1Hf5X415qnfw@mail.gmail.com>
Hi,

With the reftable backend, if one transaction updates a branch and points HEAD at it, the new HEAD reflog entry records the branch's old value. If the branch is created in the same transaction, no HEAD reflog entry is written at all. The files backend records the new value in both cases.

To reproduce on current master (fb255012ac):
  git init -q --ref-format=reftable repo && cd repo
  git commit -q --allow-empty -m one
  git commit -q --allow-empty -m two
  git branch y HEAD~
  printf '%s\n' start "update refs/heads/y $(git rev-parse HEAD)" \
          'option no-deref' 'symref-update HEAD refs/heads/y' commit |
  git update-ref -m test --stdin >/dev/null
  git log -1 --format='%h %s' HEAD
  git reflog -1 --format='%h %gs' HEAD

HEAD is at "two", but the "test" reflog entry points at "one". With --ref-format=files it points at "two".

Using "create refs/heads/z <oid>" instead of updating y leaves HEAD's reflog without a new entry.

I think the cause is write_transaction_table() in refs/reftable-backend.c. For a symref update it gets the new oid for the log record with refs_resolve_ref_unsafe() on new_target, which reads the refs as they were before the transaction. So it sees the old value of y, or no y at all, in which case the update is treated as a dangling symref and the reflog entry is skipped.

I ran into this while looking at updating a new branch and HEAD in one transaction for "git switch -c". Would taking the new oid from the target's update in the same transaction, when there is one, be the right fix? I can try to write a patch.

Thanks, Tsukasa

Next: Karthik Nayak
Message 1 of 8 in “reftable: wrong HEAD reflog when its target is updated in the same transaction”
  1. 井上司Nov 8, 2026
  2. Karthik NayakNov 8, 2026
  3. 井上司Nov 9, 2026
  4. Karthik NayakNov 9, 2026
  5. refs: fix reflog of a symref whose target is in the same transactiontsukasa inoue, Nov 10, 2026
  6. Karthik NayakNov 12, 2026
  7. 井上司Nov 13, 2026
  8. refs: fix reflog of a symref whose target is in the same transactiontsukasa inoue, Nov 17, 2026

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.