git忽略包含<要忽略的模式>的文件名. [英] git ignore filenames which contain <pattern to ignore>

查看:66
本文介绍了git忽略包含<要忽略的模式>的文件名.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图告诉git忽略文件名中有"_autosave"的文件.这样的文件的一个示例是:

I am trying to tell git to ignore files which have "_autosave" somewhere in the filename. An example of such a file is:

hats/TFCB_ATV_TOP_HAT/_autosave-TFCB_ATV_HAT.kicad_pcb

hats/TFCB_ATV_TOP_HAT/_autosave-TFCB_ATV_HAT.kicad_pcb

在正则表达式中,我只会使用模式^.*_autosave.*

In a regular expression, I would simply use the pattern ^.*_autosave.*

当然,git不使用正则表达式来评估其.gitignore文件.我读了一些书,印象是*_autosave*可以用,但不能用.

Of course, git doesn't use regular expressions to evaluate its .gitignore file. I did some reading and had the impression that *_autosave* would work, but it doesn't.

告诉git忽略这些文件的正确语法是什么?

推荐答案

将此行添加到您的.gitignore

*_autosave*

根据git help gitignore

模式相对于.gitignore文件的位置匹配

patterns match relative to the location of the .gitignore file

*_autosave*这样的模式匹配包含"_autosave"的文件或目录名称中的某处.

Patternz like *_autosave* match files or directories containing "_autosave" somewhere in the name.

以完整路径名数学化的模式中的两个连续星号("**")可能具有特殊含义

Two consecutive asterisks ("**") in patterns mathed against full pathname may have special meaning

前导"**"后跟斜杠表示在所有目录中都匹配.

A leading "**" followed by a slash means match in all directories.

但是" **/"接缝在某些环境中是多余的.

But "**/" seams redundant in some enviroments.

我的工作中的机器(使用git 1.7.1)不支持dubbel星号,但是使用*_autosave*时,它将排除文件.

My machine at work (using git 1.7.1) does not have support for dubbel asterisk, but with *_autosave* it excludes the files.

这是一个简单的测试脚本(对于Linux)

here is a simple test scrtipt (for Linux)

DIR="$(mktemp -d)"
git init $DIR/project1
cd $DIR/project1
cat > .gitignore <<EOF
**/*_autosave*
*_autosave*
EOF
mkdir dir1
touch README foo_autosave dir1/bar_autosave
git status

rm -rf $DIR/project1

这篇关于git忽略包含&lt;要忽略的模式&gt;的文件名.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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