zoukankan      html  css  js  c++  java
  • Git

    本文翻译自:Git - Ignore node_modules folder everywhere

    I have a project containing multiple other projects : 我有一个包含多个其他项目的项目:

    • Main project 主要项目
      • Mini project 1 迷你项目1
      • Mini project 2 迷你项目2

    All containing node_modules folder. 全部包含node_modules文件夹。 I want git to ignore the folder no matter where it is starting from the root folder. 我希望git忽略该文件夹,无论它从根文件夹开始。 Something like this to add in .gitignore : 像这样添加.gitignore:

    *node_modules/*
    

    #1楼

    参考:https://stackoom.com/question/217Kv/Git-忽略node-modules文件夹无处不在


    #2楼

    Add this 加上这个

    node_modules/
    

    to .gitignore file to ignore all directories called node_modules in current folder and any subfolders .gitignore文件忽略当前文件夹和任何子文件夹中名为node_modules所有目录


    #3楼

    I got into this situation a few times, so I made a one-liner I can paste into terminal in my project directory: 我进入这种情况几次,所以我做了一个单行程,我可以粘贴到我的项目目录中的终端:

    touch .gitignore && echo "node_modules/" >> .gitignore
    

    Or, when I've added the node_modules folder to git already: 或者,当我已经将node_modules文件夹添加到git时:

    git rm -r --cached node_modules && touch .gitignore && echo "node_modules/" >> .gitignore
    

    Then, validate that it worked: 然后,验证它是否有效:

    git status
    

    Explanation 说明

    touch will generate the .gitignore file if it doesn't already exist. touch将生成.gitignore文件(如果尚不存在)。

    echo and >> will append node_modules/ at the end of .gitignore , causing the node_modules folder and all subfolders to be ignored. echo>>将在.gitignore的末尾追加node_modules/ ,导致node_modules文件夹和所有子文件夹被忽略。

    git rm -r --cached removes the node_modules path from git control. git rm -r --cached从git控件中删除node_modules路径。 The flags cause the removal to be recursive and include the cache. 标志导致删除是递归的并包括缓存。


    #4楼

    First and foremost thing is to add .gitignore file in my-app. 首先,最重要的是在my-app中添加.gitignore文件。 Like so in image below. 如下图所示。

    and next add this in your .gitignore file 然后在.gitignore文件中添加它

    /node_modules
    

    Note 注意

    You can also add others files too to ignore them to be pushed on github. 您也可以添加其他文件以忽略它们在github上推送。 Here are some more files kept in .gitignore. 以下是.gitignore中保存的更多文件。 You can add them according to your requirement. 您可以根据自己的要求添加它们。 # is just a way to comment in .gitignore file. #只是在.gitignore文件中发表评论的一种方式。

    1.  
      # See https://help.github.com/ignore-files/ for more about ignoring files.
    2.  
       
    3.  
      # dependencies
    4.  
      /node_modules
    5.  
       
    6.  
      # testing
    7.  
      /coverage
    8.  
       
    9.  
      # production
    10.  
      /build
    11.  
       
    12.  
      # misc
    13.  
      .DS_Store
    14.  
      .env.local
    15.  
      .env.development.local
    16.  
      .env.test.local
    17.  
      .env.production.local
    18.  
       
    19.  
      npm-debug.log*
    20.  
      yarn-debug.log*
    21.  
      yarn-error.log*

    #5楼

    Try doing something like this 尝试做这样的事情

    **/node_modules
    

    ** is used for a recursive call in the whole project **用于整个项目中的递归调用

    Two consecutive asterisks ("**") in patterns matched against full pathname may have special meaning: 与完整路径名匹配的两个连续星号(“**”)可能具有特殊含义:

    A leading " " followed by a slash means match in all directories. 前面带有斜杠的 “ ”表示所有目录中的匹配。 For example, " /foo" matches file or directory "foo" anywhere, the same as pattern "foo". 例如,“ / foo”在任何地方匹配文件或目录“foo”,与模式“foo”相同。 "**/foo/bar" matches file or directory "bar" anywhere that is directly under directory "foo". “** / foo / bar”将文件或目录“bar”与直接位于“foo”目录下的任何位置匹配。

    A trailing "/ " matches everything inside. 尾随“/ ”匹配内部的所有内容。 For example, "abc/ " matches all files inside directory "abc", relative to the location of the .gitignore file, with infinite depth. 例如,“abc / ”匹配目录“abc”内的所有文件,相对于.gitignore文件的位置,具有无限深度。

    A slash followed by two consecutive asterisks then a slash matches zero or more directories. 斜杠后跟两个连续的星号,然后斜杠匹配零个或多个目录。 For example, "a/**/b" matches "a/b", "a/x/b", "a/x/y/b" and so on. 例如,“a / ** / b”匹配“a / b”,“a / x / b”,“a / x / y / b”等。

    Other consecutive asterisks are considered invalid. 其他连续星号被视为无效。

    Reference 参考


    #6楼

    Create .gitignore file in root folder directly by code editor or by command 通过代码编辑器或命令直接在根文件夹中创建.gitignore文件

    touch .gitignore

    open .gitignore declare folder or file name like this /foldername 打开.gitignore声明文件夹或文件名,如/ foldername

    转载:https://blog.csdn.net/xfxf996/article/details/108022822

  • 相关阅读:
    JZOJ_5838. 【广州市选2011一试】旅游路线 (Standard IO)
    JZOJ_4421. aplusb (Standard IO)
    JZOJ_3928. 射击 (Standard IO)
    JZOJ_3927. 可见点数 (Standard IO)
    AFO
    基础数论Ⅱ——笑容渐渐消失
    基础数论Ⅰ——数学渣默默流泪
    模板——二分
    模板——最小费用流
    模板——Dinic
  • 原文地址:https://www.cnblogs.com/taohuaya/p/14585010.html
Copyright © 2011-2022 走看看