本文翻译自:git ignore exception
I have a gitignore file that makes git ignore *.dll
files, and that is actually the behavior I want. 我有一个gitignore文件,使git忽略*.dll
文件,而这实际上是我想要的行为。 However, if I want an exception ( ie to be able to commit foo.dll
), how can I achieve this? 但是,如果我想要一个异常(例如,能够提交foo.dll
),如何实现呢?
#1楼
参考:https://stackoom.com/question/DRIy/git忽略异常
#2楼
To exclude everything in a directory, but some sub-directories, do the following: 要排除目录中的所有内容,但要排除某些子目录,请执行以下操作:
wp-content/*
!wp-content/plugins/
!wp-content/themes/
Source: https://gist.github.com/444295 资料来源: https : //gist.github.com/444295
#3楼
Git ignores folders if you write: 如果您这样写,Git会忽略文件夹:
/js
but it can't add exceptions if you do: !/js/jquery
or !/js/jquery/
or !/js/jquery/*
但如果执行以下操作,则无法添加例外: !/js/jquery
或!/js/jquery/
或!/js/jquery/*
You must write: 您必须写:
/js/*
and only then you can except subfolders like this 只有这样,您才能删除像这样的子文件夹
!/js/jquery
#4楼
Just add !
只需添加!
before an exclusion rule. 在排除规则之前。
According to the gitignore man page : 根据gitignore手册页 :
Patterns have the following format: 模式具有以下格式:
... ...
- An optional prefix ! 可选的前缀! which negates the pattern; 否定了模式; any matching file excluded by a previous pattern will become included again. 先前模式排除的所有匹配文件将再次包含在内。 If a negated pattern matches, this will override lower precedence patterns sources. 如果否定的模式匹配,它将覆盖优先级较低的模式源。
#5楼
Use: 采用:
*.dll #Exclude all dlls
!foo.dll #Except for foo.dll
An optional prefix ! 可选的前缀! which negates the pattern; 否定了模式; any matching file excluded by a previous pattern will become included again. 先前模式排除的所有匹配文件将再次包含在内。 If a negated pattern matches, this will override lower precedence patterns sources. 如果否定的模式匹配,它将覆盖优先级较低的模式源。
#6楼
You can simply git add -f path/to/foo.dll
. 您可以简单地git add -f path/to/foo.dll
。
.gitignore
ignores only files for usual tracking and stuff like git add .
.gitignore
只忽略用于常规跟踪的文件和诸如git add .
类的东西git add .