我有node_modules并bower_components在 .gitignore 中。每次我切换分支时,所有依赖项都会被删除(全局安装的依赖项除外),并且我必须重新安装所有依赖项。
我目前正在使用git stash save --keep-index --include-untracked \xe2\x80\x94all,但我想知道是否有一个更简单的解决方案,它可以在从另一个分支切换回来后保留 .gitignore 中的目录。
这个问题与我在 .gitignore 中记录这些目录之前在 git 索引中跟踪这些目录有关。
我执行了以下操作来解决该问题:
<directory>从 .gitignore 中删除git rm -r --cached <directory><directory>.gitignore我从如何停止跟踪并忽略 Git 中文件的更改?,它解决了我的node_modules问题,但仍有一些残留bower_components仍在跟踪中。