简体   繁体   English

.gitignore和node_modules

[英].gitignore and node_modules

I am trying to figure out the best way to handle node_modules in git. 我试图找出在git中处理node_modules的最佳方法。 From what I read, there are two options: 根据我的阅读,有两种选择:

A. Keep all the node_modules in the git repository, together with my project. A.将所有node_modules与我的项目一起保存在git存储库中。 This way, a person cloning my project does not have to install any modules. 这样,克隆我的项目的人不必安装任何模块。

B. Don't keep any node_modules in the git repository, ie, have a ".gitignore" file that contains "node_modules". B.不要在git存储库中保留任何node_modules,即,有一个包含“node_modules”的“.gitignore”文件。

However, in some projects, I don't see any of these two options. 但是,在某些项目中,我没有看到这两个选项中的任何一个。 For example, in this node.js project , there are no node_modules, but also no .gitignore file... 例如,在这个node.js项目中 ,没有node_modules,也没有.gitignore文件......

When I fork this repo, and do npm install , the folder is filled with node_modules, and since there is no .gitignore, git tries to commit them... 当我分叉这个repo并执行npm install时 ,该文件夹中填充了node_modules,由于没有.gitignore,git会尝试提交它们...

What am I doing wrong? 我究竟做错了什么?

You are not doing anything wrong, npm install will download and install all the dependencies of the project, which are defined in package.json : 你没有做错任何事, npm install将下载并安装项目的所有依赖项,这些依赖项在package.json中定义:

"dependencies": {
        "underscore" : ">=1.3.3"
    },
"devDependencies" : {
        "mocha" : ">=1.0.0",
        "canvas" : ">=0.10.0",
        "cradle" : ">=0.2.0",
        "should" : ">=0.6.0",
        "async" : ">=0.1.18"
}

There are many possible explanations as to how these do not appear in the source tree: 关于它们如何不出现在源树中,有许多可能的解释:

  • One possibility is that they are installed globally. 一种可能性是它们全球安装。
  • One other possibility is that they are actually added in .gitignore, but that .gitignore itself is never committed (this is done by adding .gitignore in the .git/info/exclude file of the project. 另一种可能性是它们实际上是在.gitignore中添加的,但是.gitignore本身永远不会被提交(这是通过在项目的.git/info/exclude文件中添加.gitignore来完成的。

In any case, the only way to know why no .gitignore exists is by asking the project's owner :). 在任何情况下,了解为什么没有.gitignore存在的唯一方法是询问项目的所有者:)。

Am not an expert for this node modules stuff but one things for sure. 我不是这个节点模块的专家,但有一点是肯定的。 If there is no .gitignore then no files are being ignored. 如果没有.gitignore,则不会忽略任何文件。 This clearly means that the committer is taking care of it manually not to commit these modules. 这显然意味着提交者正在手动处理它而不是提交这些模块。

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

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