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

Regression in :/ commit selection between 2.43.0 and 2.47.1

From
AKAarni Koskela <aarni@valohai.com>
Date
Dec 5, 2024, 12:22 UTC
Message-ID
<CAKOEJdcPYn3O01p29rVa+xv=Qr504FQyKJeSB-Moze04ViCGGg@mail.gmail.com>

The behavior of the `:/` notation to select commits seems to have changed to no longer prioritize younger commits on the current `HEAD`. Instead, if an older commit is reachable from a named ref (e.g. a tag), it will be selected instead of the younger commit.

See below for a reproduction:
* Initialize a repository
* Create a commit with message "mystery commit 1"
* Tag the commit with `git tag -a a-tag -m a-tag`
* Create another commit with message "mystery commit 2" (which should
be found from HEAD with `:/mystery`)
* Show the commit with `git show :/mystery` – it shows the older commit!
* Delete the tag with `git tag -d a-tag`
* Show the commit with `git show :/mystery` – it now shows the newer commit.

``` $ git init $ git commit -m "mystery commit 1" -m "this is old" --allow-empty [master (root-commit) 2613e98] mystery commit 1 $ git tag -a a-tag -m a-tag $ git commit -m "mystery commit 2" -m "this is newer" --allow-empty [master 705a642] mystery commit 2 $ git show :/mystery --oneline 2613e98 mystery commit 1 ```

If one deletes the tag, the younger commit is prioritized.

``` $ git tag -d a-tag Deleted tag 'a-tag' (was 652eb72) $ git show :/mystery --oneline 705a642 (HEAD -> master) mystery commit 2 ```

https://git-scm.com/docs/gitrevisions documents `:/` to find "the youngest matching commit which is reachable from any ref, including HEAD", which is how has worked before.

This seems to have regressed somewhere between Git 2.43.0 and 2.47.1. Accessing the same repository with 2.43.0 (in a Docker container) shows the expected behavior:

``` root@db58673dabff:/w# git version git version 2.43.0 root@db58673dabff:/w# git log --oneline 705a642 (HEAD -> master) mystery commit 2 2613e98 (tag: a-tag) mystery commit 1 root@db58673dabff:/w# git show :/mystery --oneline 705a642 (HEAD -> master) mystery commit 2 ```

I can also verify the same buggy behavior with 2.47.1 in an Arch Linux environment, so it's not specific to a macOS Homebrew build:

``` sh-5.2# git version git version 2.47.1 sh-5.2# git log --oneline 705a642 (HEAD -> master) mystery commit 2 2613e98 (tag: a-tag) mystery commit 1 sh-5.2# git show :/mystery --oneline 2613e98 (tag: a-tag) mystery commit 1 ```

(This can also be reproduced with a fresh repository created within that Arch Linux box with 2.47.1, so it's not e.g. a quirk of a given repository.)

This breaks my usual `git commit --fixup :/something` workflow, as a `something` commit I know I've committed just recently is no longer selected as the fixup target :-)

Best regards,
Aarni Koskela

[System Info] git version: git version 2.47.1 (from Homebrew) cpu: arm64 sizeof-long: 8 sizeof-size_t: 8 shell-path: /bin/sh feature: fsmonitor--daemon libcurl: 8.6.0 zlib: 1.2.12 uname: Darwin 23.6.0 Darwin Kernel Version 23.6.0: Thu Sep 12 23:36:12 PDT 2024; root:xnu-10063.141.1.701.1~1/RELEASE_ARM64_T6020 arm64 compiler info: clang: 16.0.0 (clang-1600.0.26.4)

Next: Jeff King
Message 1 of 3 in “Regression in :/ commit selection between 2.43.0 and 2.47.1”
  1. Aarni KoskelaDec 5, 2024
  2. Jeff KingDec 5, 2024
  3. Patrick SteinhardtDec 6, 2024

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.