2

I am trying to figure out the best way to handle node_modules in git. From what I read, there are two options:

A. Keep all the node_modules in the git repository, together with my project. 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, i.e., have a ".gitignore" file that contains "node_modules".

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...

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...

What am I doing wrong?

4

2 回答 2

8

您没有做错任何事情,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"
}

关于这些如何不出现在源代码树中有很多可能的解释:

  • 一种可能性是它们是全局安装的。
  • 另一种可能性是它们实际上是在 .gitignore 中添加的,但 .gitignore 本身从未提交(这是通过.git/info/exclude在项目文件中添加 .gitignore 来完成的。

无论如何,知道为什么不存在 .gitignore 的唯一方法是询问项目所有者:)。

于 2013-06-12T17:14:26.983 回答
2

我不是这个节点模块的专家,但肯定有一件事。如果没有 .gitignore 则不会忽略任何文件。这显然意味着提交者正在手动处理它,而不是提交这些模块。

于 2013-06-12T15:49:47.497 回答