5

I stashed my files, including a new file src/***/Microservices.jsx. Now I see it on my stash:

> git stash show
 src/***/***.jsx                 |  5 ++---
 src/***/table-view/***.jsx  |  4 ++--
 src/***/table-view/SubGroup.jsx | 37 -------------------------------------
 src/***/views.js                |  2 ++
 4 files changed, 6 insertions(+), 42 deletions(-)

> git stash show --include-untracked
 src/***/***.jsx                                    |  5 +--
 src/***/Microservices.jsx                          | 48 ++++++++++++++++++++++
 src/***/{table-view => microservices}/SubGroup.jsx | 14 ++++---
 src/***/table-view/***.jsx                     |  4 +-
 src/***/views.js                                   |  2 +
 5 files changed, 63 insertions(+), 10 deletions(-)

But no matter what I tried (applying by git stash apply [--index], git stash pop or from the git extension below), I can't apply this file.

What should I do to continue to work on this file?


Screenshot from Git Graph VSCode Extension:

stash details

You can see the Microservices.jsx file, and I can click on it and see the diff of this file inside the stash.

baruchiro
  • 5,088
  • 5
  • 44
  • 66
  • What is the output of `git stash show` and `git status`? – itamar Feb 10 '22 at 06:44
  • What happens is you git show the commit mentioned in git graph ? – Fruch Feb 10 '22 at 08:03
  • 1
    Based on [this](https://stackoverflow.com/a/12681856/7804477) answer, you could try `git show --name-only 'stash@{0}^3'` to verify if that file is in the stash. This is to ensure the extension is not causing any issues. Also, are you using `git stash apply stash@{0}` command or are you trying to apply the changes via the extension? – Gautham M Feb 10 '22 at 08:20
  • @GauthamM, I updated the question... I see the files, but still, don't know how to apply them – baruchiro Feb 10 '22 at 09:00
  • @baruchiro I think since you are able to see the diff using the extension, maybe, after taking a **backup** of the file, you may try `git stash pop stash@{0}`. Just curious to know if `pop` would succeed when `apply` fails. – Gautham M Feb 10 '22 at 09:22
  • @GauthamM same with `pop` – baruchiro Feb 10 '22 at 11:05

1 Answers1

2

This happens because your new file is not tracked. You can stash untracked files with

git stash --include-untracked

There is a new feature in git v.2.35 which allows you to work with stash just like as commit

git add -A
git stash --staged

So you first add to staging area all the files you want to stash, than check and stash it.

Mike
  • 519
  • 1
  • 4
  • 10
  • 4
    OK, this is about how to stash, but what about the current situation, the stash shows a file but can't apply it? – baruchiro Feb 10 '22 at 07:24