gpt4 book ai didi

git - 适用于 Node.js 的 `.gitignore`

转载 作者:IT老高 更新时间:2023-10-28 23:07:13 25 4
gpt4 key购买 nike

树形结构

这就是我的 Node.js 项目的组织方式:

/
| - node_modules [+ INCLUDE]
| | - my-mod1
| | | - node_modules [- IGNORE]
| | | | - external-mod1
| | | | - external-mod2
| | | - src
| | | | - node_modules [+ INCLUDE]
| | | | | - my-mod2
| | | | | - my-mod3
| | - my-mod4

我的计划

将我的项目发布到 GitHub 时:

  • 想要包含 my-mods
  • 不想包含external-mods

这意味着:

  • 想要包含顶级 /node_modules 文件夹。
  • 不想包含 node_modules 文件夹,这些文件夹是模块文件夹的直接子
  • 但我想要包含 node_moduels 文件夹,它们是 src 文件夹的子文件夹。

我做了什么

我在 /.gitignore 中添加了以下几行:

#################  
## npm
#################

npm-debug.log
node_modules/
!/node_modules/
!src/node_modules/

我的问题

我需要哪些.gitignore规则来包含正确的node_modules文件夹(如上所述)?

谢谢 - 如果有任何不清楚的地方,请发表评论。

最佳答案

由于您的结构非常有条理,您可以使用此模式来完成任务。

/node_modules/*/node-modules/ 

上述模式将忽略模块文件夹下的node_modules,my-mod1,my-mod4等。

当你推送到 github 时,上面的行仍然允许包含 src 目录下的 node_modules。

关于git - 适用于 Node.js 的 `.gitignore`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14962451/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com