.gitignore and node_modules

∥☆過路亽.° 提交于 2019-12-08 01:45:14

问题


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?


回答1:


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




回答2:


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. This clearly means that the committer is taking care of it manually not to commit these modules.



来源:https://stackoverflow.com/questions/17069782/gitignore-and-node-modules

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!