'git stash can't apply untracked file

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.



Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mike