当我改变git分支时切换node_modules文件夹 [英] Switch node_modules folder when I change git branch

查看:1159
本文介绍了当我改变git分支时切换node_modules文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与两个分支合作, master feature-1



在master分支中,我使用了一个lib xyz@1.0



分支 feature-1 我已经从lib xyz 版本 2.0安装了一个新版本< code $ $ b $ feature-1 尚未合并到 master code>分支,因为它没有完成。然后,当我再次切换到 master 时,我必须重新安装 lib@1.0 ,并且如果我再次切换至 feature-1 我必须重新安装 lib@2.0



这些案例中最好的工作流程方法是什么? 开关,你必须做你的 npm i



但是如果你经常从一个分支切换到另外,你应该考虑使用在最近的一些git版本中引入的 git worktree ,并且允许在另一个文件夹中检出另一个分支(这里特性-1 ),但共享相同的存储库(适用于此类工作流程!)。

通过这种方式,您将能够 npm i 每个分支一次,并在每个分支上并行工作。

使用起来非常简单,但我会让你看看文档。



完成后,只需删除已添加工作区的文件夹(但不包含使用.git文件夹的主文件夹!)

I'm working with two branches, master and feature-1

In the master branch I'm using a lib xyz@1.0

In the branch feature-1 I've installed a new version from lib xyz version 2.0

feature-1 was not merged yet on master branch, because it's not done. Then when I switch to master again I've to re-install the lib@1.0, and if I switch again to feature-1 I've to re-install the lib@2.0

What's the best workflow approach in theses cases?

解决方案

You do things well with git and each time you switch, you have to do your npm i.

But perhaps if you switch very often from one branch to the other, you should think about using git worktree introduced in some recent git versions and which permit to have another branch checked out in another folder (here feature-1) but sharing the same repository (perfect for this type of work flow!) .

That way you will be able to do the npm i once for each branch and work in parallel on each branch.

It's quite simple to use but I will let you have a look to the documentation.

Once you're finished, just delete the folder with the added workspace (but not the main one with the .git folder!)

这篇关于当我改变git分支时切换node_modules文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆