如何将我在node_modules中所做的更改提交回git? [英] How can I commit changes that I've made in node_modules back to git?
问题描述
有时为模块维护节点包的分支会更容易,我希望能够编辑已安装的 node_modues
模块通过 npm install githubaccount / myrepo.git
。
目前,我对文件所做的任何更改都必须复制回repo。
如何在npm中编辑模块并让它们被Git跟踪?
Python的 pip
有一个选项,您可以在其中定义一个'egg',它将repo的克隆符号链接到site_packages文件夹。我知道这是一个不同的系统,但我发现它在过去非常有用。
您可以使用 npm link
命令来执行此操作。以下是如何使用它。假设您的npm模块位于〜/ npm-module
中,并且您使用npm模块的项目位于〜/ my-project
cd〜
#首先克隆npm模块
git克隆https://..../npm-module.git
#进入模块目录:
cd npm-module
#将模块链接
npm link
#使用npm模块进入项目的CD
cd ../my-project
#链接模块
npm link npm-module
第一次调用 npm link
将在npm的缓存目录中创建一个指向npm-module本地克隆的链接。第二次调用将它链接到使用该模块的项目中(进入 node_modules
文件夹中)。
如果你看看你的项目的 node_modules
文件夹,你会看到它现在包含了一个符号链接,指向 npm-module
来源。您在该文件夹中所做的任何更改也将位于克隆的项目中。您可以在那里提交更改并将它们推送回您的远程。
这与您使用Python的 egg
功能。
以下是 npm链接文档
a>。Sometimes it's easier to maintain a fork of a node package for your module, I'd like to be able to edit a module that's in node_modues
that I've installed via npm install githubaccount/myrepo.git
.
Currently any changed that I made to a file I have to copy back to the repo. This is tedious.
How can I edit modules in npm and have them tracked by Git?
Python's pip
has an option where you can define an 'egg' which symlinks a clone of the repo to the site_packages folder. I know it's a different system, but I've found it really quite useful in the past.
You can use the npm link
command to do this. Here's how to use that. Let's assume that your npm module is located in ~/npm-module
and your project using the npm module is in ~/my-project
.
cd ~
# First clone the npm module
git clone https://..../npm-module.git
# Go into the module's directory:
cd npm-module
# Link the module
npm link
# CD into the project using the npm module
cd ../my-project
# Link the module
npm link npm-module
The first call to npm link
will create a link in npm's cache directory pointing to your local clone of the npm-module. The second call will link it into the project that's using the module (into the node_modules
folder).
If you take a look at your project's node_modules
folder, you will see that it now contains a symbolic link to the npm-module
's sources. Any changes you make in that folder will also be in the cloned project. You can commit changes there and push them back to your remote.
This is similar to what you do with Python's egg
feature.
Here's the npm link documentation.
这篇关于如何将我在node_modules中所做的更改提交回git?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!