简体   繁体   English

为什么git stash删除我的node_modules文件夹?

[英]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. 我有一个问题,当我运行git stash -u (即stash all,包括未跟踪文件)时,Git删除了我的node_modules目录。 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. 除此之外,它甚至没有在git stash pop上恢复它 - 我必须再次运行npm install才能恢复它。

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). 在.gitignore中忽略node_modules(通过行node_modules/* ),并且据我所见,从未在项目的历史中提交过( git log --all -- node_modules返回任何内容)。 Shouldn't git stash ignore it (even when committing untracked files)? 不应该git stash忽略它(即使提交未跟踪的文件)? I'm pretty sure I've used git stash like this before without any issues with node_modules. 我很确定我之前使用过git stash而没有任何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 . 更新:我已经检查了,这个问题不仅限于某个特定项目 - 它似乎发生在我运行git stash -u任何地方。 For what it's worth, my Git version is 2.6.3.windows.1 (on Windows). 值得一提的是,我的Git版本是2.6.3.windows.1(在Windows上)。

You have to change your .gitignore entry from: 您必须从以下位置更改.gitignore条目:

node_modules/*

to

node_modules/

More details here: Git Stash Can Delete Ignored Files (git stash -u) 更多细节: Git Stash可以删除被忽略的文件(git stash -u)

npm creates very long paths, which can exceed the 260 character max on Windows, depending on how long the path of your repo root is. npm创建非常长的路径,在Windows上最多可超过260个字符,具体取决于repo根路径的长度。 This could explain why you sometimes see that it works and other times not. 这可以解释为什么你有时会看到它有效,有时却没有。 If you're using npm, I suggest making sure that your repos always have a very short root path. 如果您正在使用npm,我建议确保您的repos始终具有非常短的根路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM