简体   繁体   English

使用不同的 node_modules 文件夹进行 git checkout

[英]git checkout with different node_modules folder

I have two branches, one called "gh-pages" and the other "master" branch.我有两个分支,一个叫做“gh-pages”,另一个叫做“master”分支。 Both are having separate folders like "node_modules", but they are completely different.两者都有单独的文件夹,如“node_modules”,但它们完全不同。 And they are untracked!他们没有被追踪!

So when checking out eg the "gh-pages" branch as follows因此,当检查例如“gh-pages”分支时,如下所示

git checkout gh-pages

I need a way to specify that Git should not just remove (but save) all tracked, but also all untracked files and folders (like the "node_modules" folder) from the "master" branch.我需要一种方法来指定 Git 不仅应该从“master”分支中删除(但保存)所有已跟踪的文件和文件夹(如“node_modules”文件夹),还应删除所有未跟踪的文件和文件夹(如“node_modules”文件夹)。 And then load all tracked files and folders from the "gh-pages" branch and as well as all untracked files and folders.然后从“gh-pages”分支加载所有跟踪的文件和文件夹,以及所有未跟踪的文件和文件夹。

Is there a simple way or do I really need to remove untracked files and folders for each checkout so that the two do not come into the cross?有没有一种简单的方法,或者我真的需要为每次结帐删除未跟踪的文件和文件夹,以便两者不会交叉?

I have two branches, one called "gh-pages" and the other "master" branch.我有两个分支,一个分支称为“ gh-pages”,另一个分支称为“ master”分支。 Both are having separate folders like "node_modules", but they are completely different.两者都有单独的文件夹,例如“ node_modules”,但它们完全不同。 And they are untracked!他们是无人追踪的!

So when checking out eg the "gh-pages" branch as follows因此,当签出“ gh-pages”分支时,如下所示

git checkout gh-pages

I need a way to specify that Git should not just remove (but save) all tracked, but also all untracked files and folders (like the "node_modules" folder) from the "master" branch.我需要一种方法来指定Git不仅应从“ master”分支中删除(但保存)所有跟踪的文件,而且还应删除所有未跟踪的文件和文件夹(例如“ node_modules”文件夹)。 And then load all tracked files and folders from the "gh-pages" branch and as well as all untracked files and folders.然后从“ gh-pages”分支加载所有跟踪的文件和文件夹,以及所有未跟踪的文件和文件夹。

Is there a simple way or do I really need to remove untracked files and folders for each checkout so that the two do not come into the cross?有没有一种简单的方法,或者我真的需要为每个结帐删除未跟踪的文件和文件夹,以使两者不会交叉吗?

I have two branches, one called "gh-pages" and the other "master" branch.我有两个分支,一个分支称为“ gh-pages”,另一个分支称为“ master”分支。 Both are having separate folders like "node_modules", but they are completely different.两者都有单独的文件夹,例如“ node_modules”,但它们完全不同。 And they are untracked!他们是无人追踪的!

So when checking out eg the "gh-pages" branch as follows因此,当签出“ gh-pages”分支时,如下所示

git checkout gh-pages

I need a way to specify that Git should not just remove (but save) all tracked, but also all untracked files and folders (like the "node_modules" folder) from the "master" branch.我需要一种方法来指定Git不仅应从“ master”分支中删除(但保存)所有跟踪的文件,而且还应删除所有未跟踪的文件和文件夹(例如“ node_modules”文件夹)。 And then load all tracked files and folders from the "gh-pages" branch and as well as all untracked files and folders.然后从“ gh-pages”分支加载所有跟踪的文件和文件夹,以及所有未跟踪的文件和文件夹。

Is there a simple way or do I really need to remove untracked files and folders for each checkout so that the two do not come into the cross?有没有一种简单的方法,或者我真的需要为每个结帐删除未跟踪的文件和文件夹,以使两者不会交叉吗?

I have two branches, one called "gh-pages" and the other "master" branch.我有两个分支,一个分支称为“ gh-pages”,另一个分支称为“ master”分支。 Both are having separate folders like "node_modules", but they are completely different.两者都有单独的文件夹,例如“ node_modules”,但它们完全不同。 And they are untracked!他们是无人追踪的!

So when checking out eg the "gh-pages" branch as follows因此,当签出“ gh-pages”分支时,如下所示

git checkout gh-pages

I need a way to specify that Git should not just remove (but save) all tracked, but also all untracked files and folders (like the "node_modules" folder) from the "master" branch.我需要一种方法来指定Git不仅应从“ master”分支中删除(但保存)所有跟踪的文件,而且还应删除所有未跟踪的文件和文件夹(例如“ node_modules”文件夹)。 And then load all tracked files and folders from the "gh-pages" branch and as well as all untracked files and folders.然后从“ gh-pages”分支加载所有跟踪的文件和文件夹,以及所有未跟踪的文件和文件夹。

Is there a simple way or do I really need to remove untracked files and folders for each checkout so that the two do not come into the cross?有没有一种简单的方法,或者我真的需要为每个结帐删除未跟踪的文件和文件夹,以使两者不会交叉吗?

I'm having a similar problem as well as this can also be an issue when upgrading the dependencies listed in the package.json (another branch may still have the old package.json in which case modules in node_modules could be at the wrong versions after switching branches).我有一个类似的问题,这也可能是升级package.json中列出的依赖项时的一个问题(另一个分支可能仍然有旧的package.json在这种情况下, node_modules中的模块可能在错误的版本之后切换分支)。

One of my ideas is to setup a local git checkout hook which runs npm ci every time I switch/checkout different branches or commits.我的一个想法是设置一个本地git checkout挂钩,每次我切换/签出不同的分支或提交时它都会运行npm ci This requires having/using and tracking/committing a package-lock.json however, plus (re)installing might take too long on bigger projects (in which case you may want to try something like pnpm in order to speed up installs).这需要拥有/使用和跟踪/提交package-lock.json然而,加上(重新)安装在更大的项目上可能会花费太长时间(在这种情况下,您可能想尝试pnpm之类的东西以加快安装速度)。

Another idea is to simply use yarn v2 and then commit all of your dependencies/modules (which I believe yarn stores locally in what it calls its cache ).另一个想法是简单地使用 yarn v2 然后提交所有依赖项/模块(我相信 yarn 在本地存储在它所谓的cache中)。 Also, I could be wrong but I believe you can also run npm ls and it will error if node_modules does not match the project/package manifests (not sure if this is well-documented however, nor do I know much about the finer details of what it does and doesn't verify).另外,我可能是错的,但我相信你也可以运行npm ls并且如果node_modules与项目/包清单不匹配它会出错(但是不确定这是否有详细记录,我也不太了解更详细的信息它做什么和不验证)。

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

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