Thank you for filling out a Git bug report! Please answer the following questions to help us understand your issue.
What did you do before the bug happened? (Steps to reproduce your issue) Running the following script: ``` #!/bin/bash git init workDir cd workDir git commit -m first --allow-empty echo b > b git add b GIT_TRACE=TRUE git stash push --staged --keep-index git stash pop cat b ```
What did you expect to happen? (Expected behavior) I expect file `b` to be present after running the script. If I run the script with only `git stash push --staged` or `git stash push --keep-index`, the file is present afterward.
What happened instead? (Actual behavior) The file is not present after running the script. `cat b` will report that the file does not exist.
Initialized empty Git repository in /test/workDir/.git/ [master (root-commit) 5ebd5d0] first 17:28:10.379881 git.c:459 trace: built-in: git stash push --staged 17:28:10.381318 run-command.c:654 trace: run_command: git diff-tree -p -U1 HEAD 6be660545b31f61a82a87d2b1915f0b88bb9f16f -- 17:28:10.382374 git.c:459 trace: built-in: git diff-tree -p -U1 HEAD 6be660545b31f61a82a87d2b1915f0b88bb9f16f -- 17:28:10.383488 run-command.c:654 trace: run_command: git apply -R Saved working directory and index state WIP on master: 5ebd5d0 first 17:28:10.384517 git.c:459 trace: built-in: git apply -R 17:28:10.384942 run-command.c:654 trace: run_command: git reset -q --refresh -- 17:28:10.386018 git.c:459 trace: built-in: git reset -q --refresh -- On branch master Changes to be committed: (use "git restore --staged <file>..." to unstage) new file: b
Dropped refs/stash@{0} (546ccd88cdcd416cd0bfa5b0c63600b64011da53) b
Initialized empty Git repository in /test/workDir/.git/ [master (root-commit) e972d48] first 17:26:07.021096 git.c:459 trace: built-in: git stash push --keep-index 17:26:07.022721 run-command.c:654 trace: run_command: GIT_INDEX_FILE=.git/index.stash.101 git update-index --ignore-skip-worktree-entries -z --add --remove --stdin 17:26:07.023845 git.c:459 trace: built-in: git update-index --ignore-skip-worktree-entries -z --add --remove --stdin 17:26:07.024747 run-command.c:654 trace: run_command: git reset --hard -q --no-recurse-submodules Saved working directory and index state WIP on master: e972d48 first 17:26:07.025846 git.c:459 trace: built-in: git reset --hard -q --no-recurse-submodules 17:26:07.026947 run-command.c:654 trace: run_command: git checkout --no-overlay 6be660545b31f61a82a87d2b1915f0b88bb9f16f -- :/ 17:26:07.028043 git.c:459 trace: built-in: git checkout --no-overlay 6be660545b31f61a82a87d2b1915f0b88bb9f16f -- :/ On branch master Changes to be committed: (use "git restore --staged <file>..." to unstage) new file: b
Dropped refs/stash@{0} (3ed20e369087861f1dd3089342a656217e537d34) b
Initialized empty Git repository in /test/workDir/.git/ [master (root-commit) b3f6a1b] first 17:26:28.802913 git.c:459 trace: built-in: git stash push --keep-index --staged 17:26:28.804521 run-command.c:654 trace: run_command: git diff-tree -p -U1 HEAD 6be660545b31f61a82a87d2b1915f0b88bb9f16f -- 17:26:28.805602 git.c:459 trace: built-in: git diff-tree -p -U1 HEAD 6be660545b31f61a82a87d2b1915f0b88bb9f16f -- 17:26:28.806705 run-command.c:654 trace: run_command: git apply -R Saved working directory and index state WIP on master: b3f6a1b first 17:26:28.807796 git.c:459 trace: built-in: git apply -R On branch master Changes to be committed: (use "git restore --staged <file>..." to unstage) new file: b
Changes not staged for commit: (use "git add/rm <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) deleted: b
Dropped refs/stash@{0} (0314f565bf7ae2738cece5d41045fd4dcf32aac2) cat: b: No such file or directory
`git status` reports a staged change with the created file and an unstaged change that the file is deleted.
What's different between what you expected and what actually happened? git stash pop does not recreate the file when stashing with `--staged` and `--keep-index`.
Anything else you want to add: I got the same behavior on git 2.35.1 and the latest master. I attached to output of the script for all three variants: stash push with `--staged --keep-index`, `--staged` and `--keep-index`.
[System Info] git version: git version 2.36.0.rc0 cpu: x86_64 built from commit: faa21c10d44184f616d391c158dcbb13b9c72ef3 sizeof-long: 8 sizeof-size_t: 8 shell-path: /bin/sh uname: Linux 5.10.25-linuxkit #1 SMP Tue Mar 23 09:27:39 UTC 2021 x86_64 compiler info: gnuc: 10.2 libc info: glibc: 2.31 $SHELL (typically, interactive shell): <unset>
[Enabled Hooks] not run from a git repository - no hooks to show