我正在为magento开发一个扩展.工作目录中有很多文件,但我只需要在git中包含我在扩展中添加的文件.如何为此案例定义.gitignore规则?
我试过这个 - .gitignore:
*
!/app/etc/modules/Some_Ext.xml
!/app/code/local/Some/Ext/
!/app/designer/...
... - etc.
Run Code Online (Sandbox Code Playgroud)
但是当我尝试git status时它只显示.gitignore本身.
当我用某些dirs替换星号时,它不会改变任何东西.实现目标的正确方法是什么?
dyn*_*yng 10
更新:
有一个更简单的解决方案:
*
!*/
!/app/etc/modules/Some_Ext.xml
!/app/code/local/Some/Ext/
!/app/designer/...
... - etc.
Run Code Online (Sandbox Code Playgroud)
第二行将再次包括所有目录,然后以下模式可以生效.
好吧,已经探索过源代码,我发现'gitignore'机制在某种程度上非常棘手.
一些要点总结如下:
小心忽略目录.Git以递归的方式搜索未跟踪的文件,忽略目录将导致git跳过该目录并自动忽略其下的所有文件/子目录,即使你有一个"not"-pattern.所以
/app
!/app/code/index.php
Run Code Online (Sandbox Code Playgroud)
不会保存index.php,它会被忽略/app.
尽力而为,*.xml/txt/conf/etc...改为使用.并且永远不要使用独立是一个好主意,*因为它会忽略任何目录,这可能不是你想要的.
除了订单之外没有优先权.对于目录或文件,git 逐行匹配路径并使用最后匹配的模式.如果最后匹配的模式具有前导,则git将包含文件/目录,否则将忽略它..gitignore!
所以
*.xml
!/app/etcmodules/Some_Ext.xml
Run Code Online (Sandbox Code Playgroud)
会保留Some_Ext.xml但是
!/app/etcmodules/Some_Ext.xml
*.xml
Run Code Online (Sandbox Code Playgroud)
将过滤掉它.
将git更新到1.8.2版本可能有所帮助.在1.8.2中,他们添加了一个git check-ignore用于调试.gitignore配置的命令.
我认为工作流程git add -A可以解释更多.
假设有一个像这样的存储库.
.
??? a.conf
??? b
? ??? b.conf
??? c
??? c1
??? c2
??? c.conf
Run Code Online (Sandbox Code Playgroud)
在.gitignore它是
*.conf
b/
!b/b.conf
!c/c1/c2/c.conf
Run Code Online (Sandbox Code Playgroud)
当我跑步时git add -A,git会
a.conf和两个目录b和c.a.conf相匹配*.conf的.gitignore,则忽略它.b是一个目录,而是由图案排除b/在.gitignore,停止递归到b.b被排除在外,b/b.conf从未被扫描过.(虽然他未排到第三行.gitignore)c 是一个目录,似乎并不坏,包括它并继续递归到它.c/c1/c2/c.conf匹配两种模式,但最后一种决定了命运.因为最后匹配的模式!c/c1/c2/c.conf具有领先优势!,c/c1/c2/c.conf将存活下来.这是git add -A我的机器的结果(Mac版本为1.8.2的git)
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: .gitignore
# new file: c/c1/c2/c.conf
Run Code Online (Sandbox Code Playgroud)