{"thread":{"id":"62838","subject":"git stash pop fails in specific git repository","startedAt":"2025-01-21T15:55:28Z","lastAt":"2025-01-21T15:55:28Z","messageCount":1,"participants":["Martin"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"511003","messageId":"874ebe66-ad52-43fe-b6c6-3ec5143b5401@gregoire.de","threadId":"62838","inReplyTo":null,"subject":"git stash pop fails in specific git repository","fromName":"Martin","fromEmail":"m+dev@gregoire.de","sentAt":"2025-01-21T15:55:21Z","receivedAt":"2025-01-21T15:55:28Z","isPatch":false,"sender":{"key":"m+dev@gregoire.de","avatar":null},"body":"Thank you for filling out a Git bug report!\nPlease answer the following questions to help us understand your issue.\n\nWhat did you do before the bug happened? (Steps to reproduce your issue)\n\nTried to pop a stash by running `git stash pop 'stash@{0}'`.\nPlease note that I'm using \"stash@{0}\" as a reference here.\nWhen using \"0\", or omitting the reference, `git stash pop` succeeds.\nDetails below.\n\nWhat did you expect to happen? (Expected behavior)\n\nThe most recent stash to be applied, then dropped.\n\nWhat happened instead? (Actual behavior)\n\nThe stash was not applied or dropped.\nAn exit code of 1 was returned, with no error message.\n\nAnything else you want to add:\n\nThis only happens in a specific git repository, but is reproducible there.\nThe issue does *not* happen in a fresh git repository.\n\nAn example of a fresh git repository and the expected behavior:\n\n```shell\n# setup\n$ git init\nInitialized empty Git repository in /home/user/tmp/new/.git/\n$ echo hello >> README.md\n$ git add .\n$ git commit -m \"Init\"\n[main (root-commit) 3fb3ed1] Init\n  1 file changed, 1 insertion(+)\n  create mode 100644 README.md\n\n# stash creation\n$ echo world >> README.md\n$ git stash push\nSaved working directory and index state WIP on main: 3fb3ed1 Init\n\n# stash pop succeeds\n$ git stash pop 'stash@{0}'\nOn branch main\nChanges not staged for commit:\n   (use \"git add <file>...\" to update what will be committed)\n   (use \"git restore <file>...\" to discard changes in working directory)\n   modified:   README.md\n\nno changes added to commit (use \"git add\" and/or \"git commit -a\")\nDropped stash@{0} (272c93ac3fe3cf69380a61ccaba0d90509e306f0)\n```\n\nThis is what happens in the git repository that shows this issue:\n\n```shell\n# setup\n$ git clone git@github.com:some/thing.git\n$ cd thing\n$ git status\nOn branch production\nYour branch is up to date with 'origin/production'.\n\nnothing to commit, working tree clean\n\n# stash creation\n$ echo something >> README.md\n$ git status\nOn branch production\nYour branch is up to date with 'origin/production'.\n\nChanges not staged for commit:\n   (use \"git add <file>...\" to update what will be committed)\n   (use \"git restore <file>...\" to discard changes in working directory)\n   modified:   README.md\n\nno changes added to commit (use \"git add\" and/or \"git commit -a\")\n$ git stash push\nSaved working directory and index state WIP on production: abcd1234\nMerge pull request #1234 from some/feature/branch\n$ git --no-pager stash list\nstash@{0}: WIP on production: abcd1234 Merge pull request #1234 from\nsome/feature/branch\n\n# stash pop fails\n$ git stash pop 'stash@{0}' # no output from this command\n$ echo $?\n1\n```\n\nThe same error happens when using these commands:\n\n```shell\n$ git stash pop \"stash@{0}\"\n$ git stash pop stash@{0}\n```\n\nThe error does *not* happen when popping the stash like this:\n\n```shell\n$ git stash pop 0 # or \"git stash pop\" without any ref\nOn branch production\nYour branch is up to date with 'origin/production'.\n\nChanges not staged for commit:\n   (use \"git add <file>...\" to update what will be committed)\n   (use \"git restore <file>...\" to discard changes in working directory)\n   modified:   README.md\n\nno changes added to commit (use \"git add\" and/or \"git commit -a\")\nDropped refs/stash@{0} (3f0ed5a45d2eab357cfc47a9ff8a4f86faabf66c)\n```\n\nI added some trace environment variables, maybe this helps:\n\n```shell\n$ GIT_TRACE=2 GIT_TRACE_PACK_ACCESS=2 GIT_TRACE_PACKET=2\nGIT_TRACE_PACKFILE=2 GIT_TRACE_SETUP=2 GIT_TRACE_SHALLOW=2 git stash pop\n'stash@{0}'\n16:02:21.941329 trace.c:387             setup: git_dir: .git\n16:02:21.941358 trace.c:388             setup: git_common_dir: .git\n16:02:21.941362 trace.c:389             setup: worktree:\n/home/user/tmp/thing\n16:02:21.941365 trace.c:390             setup: cwd: /home/user/tmp/thing\n16:02:21.941367 trace.c:391             setup: prefix: (null)\n16:02:21.941373 chdir-notify.c:65       setup: chdir from\n'/home/user/tmp/thing' to '/home/user/tmp/thing'\n16:02:21.941379 git.c:455               trace: built-in: git stash pop\n'stash@{0}'\nerror: stash@{0} is not a valid reference\n```\n\nHere we see an error message for the first time.\nI do not know why this is not shown by the previous commands, maybe\nthat's related to my shell.\nThe same error message is shown when running the commands with stderr\nredirection:\n\n```shell\n$ git stash pop 'stash@{0}' 2>&1\nerror: stash@{0} is not a valid reference\n$ git stash pop \"stash@{0}\" 2>&1\nerror: stash@{0} is not a valid reference\n$ git stash pop stash@{0} 2>&1\nerror: stash@{0} is not a valid reference\n```\n\nI do not understand this error message, as the reference \"stash@{0}\"\nmatches the one from the `git --no-pager stash list` command.\n\nHow can I debug the affected git repository to find out more? The\nrepository is private, so unfortunately I cannot share it.\n\n\n[System Info]\ngit version:\ngit version 2.34.1\ncpu: x86_64\nno commit associated with this build\nsizeof-long: 8\nsizeof-size_t: 8\nshell-path: /bin/sh\nuname: Linux 5.15.0-130-generic #140-Ubuntu SMP Wed Dec 18 17:59:53 UTC\n2024 x86_64\ncompiler info: gnuc: 11.4\nlibc info: glibc: 2.35\n$SHELL (typically, interactive shell): /usr/bin/zsh\n\nNote: I also compiled git version 2.48.1 from source (using `NO_CURL=1\nmake`), the issue is the same.\n\nNote: switching from zsh to bash does not help, the issue is the same.\n\n[Enabled Hooks]\n"}]}