代码之家  ›  专栏  ›  技术社区  ›  roundcrisis

git忽略异常

  •  265
  • roundcrisis  · 技术社区  · 15 年前

    我有一个gitinore文件,它使git忽略 *.dll 文件,这就是我想要的行为。但是,如果我想要一个异常(即能够提交 foo.dll

    9 回复  |  直到 15 年前
        1
  •  504
  •   Skilldrick    15 年前

    *.dll    #Exclude all dlls
    !foo.dll #Except for foo.dll
    

    gitignore

    可选前缀!否定了这种模式;被先前模式排除的任何匹配文件都将再次被包括在内。如果取反的模式匹配,这将覆盖优先级较低的模式源。

        2
  •  297
  •   Matiss    12 年前

    如果写入以下内容,Git将忽略文件夹:

    /js
    

    但如果您这样做,它就不能添加例外: !/js/jquery !/js/jquery/ !/js/jquery/*

    你必须写:

    /js/* 
    

    !/js/jquery
    
        3
  •  59
  •   nocksock    15 年前

    你可以简单地 git add -f path/to/foo.dll .

    .gitignore git add .

        4
  •  20
  •   Simon Paarlberg    13 年前

    要排除目录中的所有内容,但排除某些子目录,请执行以下操作:

    wp-content/*
    !wp-content/plugins/
    !wp-content/themes/
    

    https://gist.github.com/444295

        5
  •  15
  •   Robert Munteanu    15 年前

    只需添加 !

    根据 gitignore man page :

    ...

    • 可选前缀!否定了这种模式;被先前模式排除的任何匹配文件都将再次被包括在内。如果取反的模式匹配,这将覆盖优先级较低的模式源。
        6
  •  5
  •   Tobias Kienzler    15 年前

    !foo.dll 在.git中忽略,或者(每次!) git add -f foo.dll

        7
  •  5
  •   DeanOC Ben Moreton    8 年前

    如果您使用的是Visual Studio,而您的.dll恰好位于 bin

    !SourceCode/Solution/Project/bin
    !SourceCode/Solution/Project/bin/My.dll
    

    这是因为默认的visualstudio .gitignore 文件包含的忽略模式 [Bbin]/

    此模式将清除所有bin文件夹(以及它们的内容),这使得任何包含内容的尝试都是多余的(因为文件夹本身已经被忽略)。

    我能够找到为什么我的文件不被排除在运行

    git check-ignore -v -- SourceCode/Solution/Project/bin/My.dll
    

    从Git Bash窗口。这件事回报了 [英国广播公司]/

        8
  •  4
  •   Community Mohan Dere    8 年前

    解决方案取决于git ignore规则和exception规则之间的关系:

    1. 文件/同级文件:使用 @Skilldrick solution .
    2. 文件夹/子文件夹:使用 @Matiss Jurgelis solution
    3. 不同级别的文件/文件或文件/子文件夹:可以执行以下操作:

      *.suo
      *.user
      *.userosscache
      *.sln.docstates
      
      # ...
      
      # Exceptions for entire subfolders
      !SetupFiles/elasticsearch-5.0.0/**/*
      !SetupFiles/filebeat-5.0.0-windows-x86_64/**/*
      
      # Exceptions for files in different levels
      !SetupFiles/kibana-5.0.0-windows-x86/**/*.suo
      !SetupFiles/logstash-5.0.0/**/*.suo
      
        9
  •  1
  •   Erfan    5 年前

    由于git2.7.0git将考虑异常。从官方发行说明中:

    • 允许稍后“/abc/def“覆盖先前的“/abc”命令 出现在同一个.gitignore文件中,以使其更易于表达 “忽略/abc目录中的所有内容,除了…”。

    https://raw.githubusercontent.com/git/git/master/Documentation/RelNotes/2.7.0.txt

        10
  •  0
  •   Miladiouss    4 年前

    我是这样做的,每个目录中都有一个README.md文件:

    /data/*
    !/data/README.md
    
    !/data/input/
    /data/input/*
    !/data/input/README.md
    
    !/data/output/
    /data/output/*
    !/data/output/README.md