{"thread":{"id":"57670","subject":"file loss by git stash push --staged --keep-index","startedAt":"2022-04-05T21:50:15Z","lastAt":"2022-04-05T21:50:15Z","messageCount":1,"participants":["Maximilian Reichel"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"453143","messageId":"111D7753-AE53-4906-A7AF-F39EA7455CA3@icloud.com","threadId":"57670","inReplyTo":null,"subject":"file loss by git stash push --staged --keep-index","fromName":"Maximilian Reichel","fromEmail":"reichemn@icloud.com","sentAt":"2022-04-05T17:48:11Z","receivedAt":"2022-04-05T21:50:15Z","isPatch":false,"sender":{"key":"reichemn@icloud.com","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)\nRunning the following script:\n```\n#!/bin/bash\ngit init workDir\ncd workDir\ngit commit -m first --allow-empty\necho b > b\ngit add b\nGIT_TRACE=TRUE git stash push --staged --keep-index\ngit stash pop\ncat b\n```\n\nWhat did you expect to happen? (Expected behavior)\nI expect file `b` to be present after running the script.\nIf I run the script with only `git stash push --staged` or \n`git stash push --keep-index`, the file is present afterward.\n\nWhat happened instead? (Actual behavior)\nThe file is not present after running the script.\n`cat b` will report that the file does not exist.\n\nInitialized empty Git repository in /test/workDir/.git/\n[master (root-commit) 5ebd5d0] first\n17:28:10.379881 git.c:459               trace: built-in: git stash push --staged\n17:28:10.381318 run-command.c:654       trace: run_command: git diff-tree -p -U1 HEAD 6be660545b31f61a82a87d2b1915f0b88bb9f16f --\n17:28:10.382374 git.c:459               trace: built-in: git diff-tree -p -U1 HEAD 6be660545b31f61a82a87d2b1915f0b88bb9f16f --\n17:28:10.383488 run-command.c:654       trace: run_command: git apply -R\nSaved working directory and index state WIP on master: 5ebd5d0 first\n17:28:10.384517 git.c:459               trace: built-in: git apply -R\n17:28:10.384942 run-command.c:654       trace: run_command: git reset -q --refresh --\n17:28:10.386018 git.c:459               trace: built-in: git reset -q --refresh --\nOn branch master\nChanges to be committed:\n  (use \"git restore --staged <file>...\" to unstage)\n\tnew file:   b\n\nDropped refs/stash@{0} (546ccd88cdcd416cd0bfa5b0c63600b64011da53)\nb\n\n\nInitialized empty Git repository in /test/workDir/.git/\n[master (root-commit) e972d48] first\n17:26:07.021096 git.c:459               trace: built-in: git stash push --keep-index\n17: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\n17:26:07.023845 git.c:459               trace: built-in: git update-index --ignore-skip-worktree-entries -z --add --remove --stdin\n17:26:07.024747 run-command.c:654       trace: run_command: git reset --hard -q --no-recurse-submodules\nSaved working directory and index state WIP on master: e972d48 first\n17:26:07.025846 git.c:459               trace: built-in: git reset --hard -q --no-recurse-submodules\n17:26:07.026947 run-command.c:654       trace: run_command: git checkout --no-overlay 6be660545b31f61a82a87d2b1915f0b88bb9f16f -- :/\n17:26:07.028043 git.c:459               trace: built-in: git checkout --no-overlay 6be660545b31f61a82a87d2b1915f0b88bb9f16f -- :/\nOn branch master\nChanges to be committed:\n  (use \"git restore --staged <file>...\" to unstage)\n\tnew file:   b\n\nDropped refs/stash@{0} (3ed20e369087861f1dd3089342a656217e537d34)\nb\n\n\nInitialized empty Git repository in /test/workDir/.git/\n[master (root-commit) b3f6a1b] first\n17:26:28.802913 git.c:459               trace: built-in: git stash push --keep-index --staged\n17:26:28.804521 run-command.c:654       trace: run_command: git diff-tree -p -U1 HEAD 6be660545b31f61a82a87d2b1915f0b88bb9f16f --\n17:26:28.805602 git.c:459               trace: built-in: git diff-tree -p -U1 HEAD 6be660545b31f61a82a87d2b1915f0b88bb9f16f --\n17:26:28.806705 run-command.c:654       trace: run_command: git apply -R\nSaved working directory and index state WIP on master: b3f6a1b first\n17:26:28.807796 git.c:459               trace: built-in: git apply -R\nOn branch master\nChanges to be committed:\n  (use \"git restore --staged <file>...\" to unstage)\n\tnew file:   b\n\nChanges not staged for commit:\n  (use \"git add/rm <file>...\" to update what will be committed)\n  (use \"git restore <file>...\" to discard changes in working directory)\n\tdeleted:    b\n\nDropped refs/stash@{0} (0314f565bf7ae2738cece5d41045fd4dcf32aac2)\ncat: b: No such file or directory\n\n\n\n`git status` reports a staged change with the created file and \nan unstaged change that the file is deleted.\n\nWhat's different between what you expected and what actually happened?\ngit stash pop does not recreate the file when stashing with\n`--staged` and `--keep-index`.\n\nAnything else you want to add:\nI got the same behavior on git 2.35.1 and the latest master.\nI attached to output of the script for all three variants:\nstash push with `--staged --keep-index`, `--staged` and `--keep-index`.\n\n[System Info]\ngit version:\ngit version 2.36.0.rc0\ncpu: x86_64\nbuilt from commit: faa21c10d44184f616d391c158dcbb13b9c72ef3\nsizeof-long: 8\nsizeof-size_t: 8\nshell-path: /bin/sh\nuname: Linux 5.10.25-linuxkit #1 SMP Tue Mar 23 09:27:39 UTC 2021 x86_64\ncompiler info: gnuc: 10.2\nlibc info: glibc: 2.31\n$SHELL (typically, interactive shell): <unset>\n\n\n[Enabled Hooks]\nnot run from a git repository - no hooks to show\n\n"}]}