.gitignore和node_modules [英] .gitignore and node_modules

查看:355
本文介绍了.gitignore和node_modules的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出在git中处理node_modules的最佳方法。从我读到的,有两种选择:

A。将所有node_modules与我的项目一起保存在git存储库中。这样,克隆我的项目的人就不必安装任何模块。

B。不要在git仓库中保留任何node_modules,即有一个包含node_modules的.gitignore文件。

然而,在某些项目中,没有看到这两个选项中的任何一个。例如,在此node.js项目中,没有node_modules,也没有.gitignore文件.. 。

当我分叉这个repo并执行 npm install 时,文件夹被node_modules填充,并且由于没有.gitignore,git尝试提交它们...



我在做什么错?

你没有做错任何事情, 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本身永远不会被提交(这是通过在<$ c $中添加.gitignore来完成的c> .git / info / exclude 项目文件。



无论如何,要知道为什么没有.gitignore存在是通过询问该项目的所有者:)。


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?

解决方案

You are not doing anything wrong, npm install will download and install all the dependencies of the project, which are defined in 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.

In any case, the only way to know why no .gitignore exists is by asking the project's owner :).

这篇关于.gitignore和node_modules的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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