Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is git stash removing my node_modules folder?

I'm having an issue where when I run git stash -u (ie. stash all, including untracked files), Git removes my node_modules directory. On top of this, it doesn't even restore it on git stash pop - I have to run npm install again to get it back.

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

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

like image 729
Nick F Avatar asked Nov 20 '22 06:11

Nick F


1 Answers

You have to change your .gitignore entry from:

node_modules/*

to

node_modules/

More details here: Git Stash Can Delete Ignored Files (git stash -u)

like image 199
Jojo Avatar answered Dec 09 '22 12:12

Jojo