rsync根据.gitignore& amp; amp; .hgignore& svn:忽略像--filter =:C [英] rsync exclude according to .gitignore & .hgignore & svn:ignore like --filter=:C

查看:220
本文介绍了rsync根据.gitignore& amp; amp; .hgignore& svn:忽略像--filter =:C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Rsync包含一个漂亮的选项 - cvs-exclude 来以与CVS相同的方式忽略文件,但是CVS已经过时多年了。有什么办法可以让它排除现代版本控制系统(Git,Mercurial,Subversion)会忽略的文件吗?

例如,我有很多Maven从GitHub签出的项目。通常它们包含一个 .gitignore ,它至少列出 target ,默认的Maven构建目录(可能出现在顶层或子模块中)。由于这些目录的内容完全是一次性的,并且它们可能远远大于源代码,所以我想在使用rsync进行备份时将它们排除在外。



当然,我可以显式地 - exclude = target / ,但是这会意外地抑制刚刚被命名为 target 且无关的目录不应该被忽略。



我可以提供任何 .gitignore 中提及的所有文件名和模式的绝对路径的完整列表。 code>, .hgignore svn:ignore 属性,但这将是一个巨大的列表必须由某种脚本产生。



由于rsync没有内置的对CVS以外的VCS签出的支持,是否有任何好的诀窍它们忽视模式?或者某种回调系统,用户脚本可以被询问是否应该包含给定的文件/目录?



更新 - filter =': - .gitignore'按照LordJavac的建议似乎也适用于Git,如 - filter =:C 对CVS是有效的,尽管目前还不清楚语法是否完全匹配。 - filter =': - .hgignore'对于Mercurial并不适用;例如一个 .hgignore 包含一行如 ^ target $ (Meritial等效于Git / target / )不能被rsync识别为正则表达式。对于Subversion来说,没有任何东西可以工作,对于1.6或更低版本的工作副本,您必须解析 .svn / dir-prop-base ,然后举起手来如果你有一个1.7或更高版本的工作副本,可能会感到沮丧。

正如luksan所提到的,你可以用 - filter 切换到 rsync 。我用 - filter =': - .gitignore'(在.gitignore之前有一个空格)告诉 rsync .gitignore 文件做一个目录合并,让它们按照git的规则排除。如果有的话,您可能还想添加全局忽略文件。为了便于使用,我创建了一个包含过滤器的 rsync 的别名。


Rsync includes a nifty option --cvs-exclude to "ignore files in the same way CVS does", but CVS has been obsolete for years. Is there any way to make it also exclude files which would be ignored by modern version control systems (Git, Mercurial, Subversion)?

For example, I have lots of Maven projects checked out from GitHub. Typically they include a .gitignore listing at least target, the default Maven build directory (which may be present at top level or in submodules). Since the contents of these directories are entirely disposable, and they can be far larger than source code, I would like to exclude them when using rsync for backups.

Of course I can explicitly --exclude=target/ but that will accidentally suppress unrelated directories that just happen to be named target and are not supposed to be ignored.

And I could supply a complete list of absolute paths for all file names and patterns mentioned in any .gitignore, .hgignore, or svn:ignore property on my disk, but this would be a huge list that would have to be produced by some sort of script.

Since rsync has no built-in support for VCS checkouts other than CVS, is there any good trick for feeding it their ignore patterns? Or some kind of callback system whereby a user script can be asked whether a given file/directory should be included or not?

Update: --filter=':- .gitignore' as suggested by LordJavac seems to work as well for Git as --filter=:C does for CVS, at least on the examples I have found, though it is unclear if the syntax is an exact match. --filter=':- .hgignore' does not work very well for Mercurial; e.g. an .hgignore containing a line like ^target$ (the Mercurial equivalent of Git /target/) is not recognized by rsync as a regular expression. And nothing seems to work for Subversion, for which you would have to parse .svn/dir-prop-base for a 1.6 or earlier working copy, and throw up your hands in dismay for a 1.7 or later working copy.

解决方案

As mentioned by luksan, you can do this with the --filter switch to rsync. I achieved this with --filter=':- .gitignore' (there's a space before ".gitignore") which tells rsync to do a directory merge with .gitignore files and have them exclude per git's rules. You may also want to add your global ignore file, if you have one. To make it easier to use, I created an alias to rsync which included the filter.

这篇关于rsync根据.gitignore& amp; amp; .hgignore& svn:忽略像--filter =:C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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