我有一个项目包含多个其他项目:

主要项目 小项目1 小项目2

所有包含node_modules文件夹。我想要git忽略文件夹,无论它是从根文件夹开始的位置。在.gitignore中添加如下内容:

*node_modules/*

当前回答

如果你的子项目/客户端node_modules被提交,

    # dependencies
    /node_modules
    /.pnp
    .pnp.js

    # testing
    /coverage

    # production
    /build

    # misc
    .DS_Store
    .env.local
    .env.development.local
    .env.test.local
    .env.production.local

    npm-debug.log*
    yarn-debug.log*
    yarn-error.log*

然后在最后一行添加“node_modules”。

    # dependencies
    /node_modules
    /.pnp
    .pnp.js

    # testing
    /coverage

    # production
    /build

    # misc
    .DS_Store
    .env.local
    .env.development.local
    .env.test.local
    .env.production.local

    npm-debug.log*
    yarn-debug.log*
    yarn-error.log*
    node_modules 
    # ------ Up Here ------

其他回答

只需在小项目1和小项目2中添加不同的.gitignore文件。每个.gitignore文件都应该/node_modules,这样就可以了。

敌人谁是尝试上述答案,仍然面临的问题

我已经尝试了几乎所有的答案,最终,它解决了我忽略node_modules的问题,但只有在我提交更改之后!

如果你的子项目/客户端node_modules被提交,

    # dependencies
    /node_modules
    /.pnp
    .pnp.js

    # testing
    /coverage

    # production
    /build

    # misc
    .DS_Store
    .env.local
    .env.development.local
    .env.test.local
    .env.production.local

    npm-debug.log*
    yarn-debug.log*
    yarn-error.log*

然后在最后一行添加“node_modules”。

    # dependencies
    /node_modules
    /.pnp
    .pnp.js

    # testing
    /coverage

    # production
    /build

    # misc
    .DS_Store
    .env.local
    .env.development.local
    .env.test.local
    .env.production.local

    npm-debug.log*
    yarn-debug.log*
    yarn-error.log*
    node_modules 
    # ------ Up Here ------

在.gitignore中添加下面的行将忽略整个存储库中的节点模块。

node_modules

遵循以下步骤-

在项目所在的文件夹上打开git bash,或者打开vs code终端 按

CTRL + `

在终端中写入[echo > .gitignore]或创建文件[。Gitignore]直接进入文件夹 然后将其写入忽略整个存储库中的节点模块

node_modules

或者,尝试忽略来自多个子文件夹的所有node_modules

**node_modules

注意:如果你在输入文件夹或文件的名称时出现拼写错误,它将无法工作。所以,仔细检查拼写