Why does git stash delete my node_modules folder?

I had a problem, when I run git stash -u (i.e. all files, including unplayable files), Git deletes my node_modules directory. Also, it doesn't even restore it to git stash pop - I need to run npm install again to get it back.

node_modules is ignored in .gitignore (via the node_modules/* ), and as far as I can see, it has never been executed in the project history ( git log --all -- node_modules nothing). Shouldn't git stash ignore it (even when committing unprepared files)? I am pretty sure I used git stash like this before without any problems with node_modules.

Update: I checked, and this problem is not limited to a specific project - it seems to happen anywhere I run git stash -u . For what it's worth, my version of Git is 2.6.3.windows.1 (on Windows).

+5
source share
2 answers

You must change your .gitignore entry:

 node_modules/* 

to

 node_modules/ 

Read more here: Git Stash Can Delete Ignored Files (git stash -u)

+1
source

npm creates very long paths that can exceed a maximum of 260 characters on Windows, depending on how long your repo root path takes. This may explain why you sometimes see it working, and sometimes not. If you use npm, I suggest making sure your repositories always have a very short root path.

-1
source

All Articles