1

我正在建立一个 Lemonstand 网站,我正在通过 git 进行管理。因此,我使用以下 .gitignore 规则:

# Lemonstand
.htaccess
php.ini
boot.php
index.php
install.php
/config/*
/controllers/*
/init/*
/logs/*
/phproad/*
/temp/*
/uploaded/*
/installer_files/*
/modules/backend/*
/modules/blog/*
/modules/cms/*
/modules/core/*
/modules/session/*
/modules/shop/*
/modules/system/*
/modules/users/*
# add content_*.php if you don't want erase client changes to content

/modules/gallery/*
/modules/lddevel/*
/modules/tweak/*

(我从 github 获得的顶部块,第二块是我自己添加的一些附加规则,以避免 Lemonstands 更新系统出现问题)。

我的问题是我正在向 Lemonstand 添加一个自定义发票,这(长话短说)需要在 中添加一个文件夹和一些文件/modules/shop/invoice_templates/,我将其命名为cm_standard.

因为这是默认 Lemonstand 的额外内容,所以我想用 git 跟踪它,所以我尝试在我的 gitignore 文件底部使用以下规则:

!/modules/shop/invoice_templates/cm_standard/*

但是当我做 a 时git add -A,它并没有拾取该目录中的文件。即使我这样做,git add modules/shop/invoice_templates/cm_standard/*它也会告诉我:

The following paths are ignored by one of your .gitignore files:
modules/shop/invoice_templates
Use -f if you really want to add them.
fatal: no files added

这进一步表明我没有正确编写规则 - 任何人都可以帮忙吗?谢谢你。

4

1 回答 1

1

忽略具有较少路径段的模式可以优先于具有更多路径段的模式,因此在您的情况下/modules/shop/*优先于!/modules/shop/invoice_templates/cm_standard/*/modules/shop/invoice_templates/甚至在它查看 !/modules/shop/invoice_templates/cm_standard. 话虽如此,排序也很重要,当它发生时,文件中有点违反直觉的后来的规则优先于早期的规则。

这个问题与 gitignore 排除规则如何实际工作非常相似所以我建议你读一下。此外,您可能会发现该子命令在调试规则check-ignore时很有用- 我在过去几个月将它添加到 git,它刚刚出现在几天前发布的 1.8.2 版本中。

于 2013-03-18T18:43:08.903 回答