Git是否更改了“!"? .gitignore的前缀行为? [英] Did Git change the "!" prefix behavior at .gitignore?

查看:110
本文介绍了Git是否更改了“!"? .gitignore的前缀行为?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Git 2.7发行说明中找到了下面的句子.

I found a below sentence in Git 2.7 Release Notes.

  • 允许更高版本的!/abc/def"覆盖之前的"/abc" 出现在同一.gitignore文件中,以便于表达 "/abc目录中的所有内容都将被忽略,除了...".

  • Allow a later "!/abc/def" to override an earlier "/abc" that appears in the same .gitignore file to make it easier to express "everything in /abc directory is ignored, except for ...".

Git 2.7发行说明

但是,此功能在后续版本中似乎无效.

However, This function seems to be invalid in subsequent versions.

$ git --version
git version 2.19.1
$  cat .gitignore
/abc
!/abc/def
$ mkdir abc
$ echo foo > abc/def
$ git status
On branch master
nothing to commit, working tree clean

Git更改了!" .gitignore的前缀行为?还是我弄错了?

Did Git change the "!" prefix behavior at .gitignore? Or did I mistake?

推荐答案

看起来该更改已在2.8.0中恢复,为什么要梳理已有两年历史的发行说明,看看gitignore的行为如何,您只能说git help ignore它会告诉你

It looks like that change was reverted in 2.8.0, why are you combing two-year-old release notes to see how gitignore behaves when you could just say git help ignore and it'd tell you

  • 可选的前缀!"否定了模式;先前模式排除的所有匹配文件将再次包含在内. 如果排除了该文件的父目录,则无法重新包含该文件. 出于性能原因,Git不会列出排除的目录,因此包含的任何模式文件无论在何处定义都无效.在第一个!"前面加一个反斜杠("\").用于以文字!"开头的模式,例如!important!.txt".
  • An optional prefix "!" which negates the pattern; any matching file excluded by a previous pattern will become included again. It is not possible to re-include a file if a parent directory of that file is excluded. Git doesn’t list excluded directories for performance reasons, so any patterns on contained files have no effect, no matter where they are defined. Put a backslash ("\") in front of the first "!" for patterns that begin with a literal "!", for example, "!important!.txt".

如果不想删除忽略目录,执行gitignores的简单方法是忽略它们的全部内容

The easy way to do your gitignores if you don't want the ignored-directory pruning is to ignore their entire contents with

directory/**

被任何替代(例如您的!directory/def)和gitignore put的末尾

follwed by any overrides, (e.g. your !directory/def) and at the end of your gitignore put

!*/

之后是您真正打算实现的所有完全排除.

followed by any complete exclusions you really meant for effect.

这篇关于Git是否更改了“!"? .gitignore的前缀行为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆