如何在gitignore中使用条件 [英] How to use conditions in gitignore

查看:179
本文介绍了如何在gitignore中使用条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用git管理多个 pdf graffle 文件。只有当 graffle 具有相同的文件名不存在时,我才会将 pdf 文件添加到存储库, g。



只添加 foo.pdf bar.graffle 存储到目录中的存储库中

  $ ls 
foo.pdf
bar.pdf
bar.graffle

如果只有 gitignore才能完成此目标,有没有解决方法?



bar.pdf 只能使用 bar.graffle 通过GUI中的几个步骤,所以我想让它们保持提交状态。 注意 .gitignore 仅存在于 git 的提示中,以指明哪些文件,目录或文件类型将被 git add忽略



然而, .gitignore 不会停止任何文件添加到存储库如果您使用 git add -f



长话短说, .gitignore code>是相当简单的机制,有助于避免意外添加典型的垃圾文件(如编辑器备份,目标文件,可执行文件等),但它不够复杂,无法满足您的要求 - 如更改行为取决于一些外部条件。



如果您不需要添加某些文件,或者添加 git add -f ,因此o或者,您可以创建一些脚本并将其注册为git宏,如 git addc ,它表示会做这样的高级过滤。


I'm managing several pdf and graffle files with git. I want to add pdf files to repository only if graffle with same filename does not exists, e. g.

only add foo.pdf and bar.graffle into repository in the directory

$ ls
foo.pdf
bar.pdf
bar.graffle

If such target can't be completed only with gitignore, is there any work arounds exist?

bar.pdf can only be generated with bar.graffle through several steps in GUI, so I want to keep them on commit.

解决方案

Note that .gitignore only exists as a hint to git as to which files, directories or file types will be ignored by git add.

However, .gitignore will not stop any file to be added into repository if you use git add -f.

Long story short, .gitignore is rather simplistic mechanism that helps to avoid accidentally adding typical junk files (like editor backups, object files, executables, etc.), but it is not sophisticated enough to be capable of what you are asking for - like changing behaviour depending on some external conditions.

You can be careful not to add some files if you don't want them, or add ignored files with git add -f and thus overriding existing simple rules.

Alternatively, you can create some script and register it as git macro like git addc that will do such advanced filtering.

这篇关于如何在gitignore中使用条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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