title: rsync exclude according to .gitignore & .hgignore & svn:ignore like --filter=:C
body: <p>Rsync includes a nifty option <code>--cvs-exclude</code> 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)?</p>
  
  <p>For example, I have lots of Maven projects checked out from GitHub. Typically they include a <code>.gitignore</code> listing at least <code>target</code>, 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.</p>
  
  <p>Of course I can explicitly <code>--exclude=target/</code> but that will accidentally suppress unrelated directories that just happen to be named <code>target</code> and are not supposed to be ignored.</p>
  
  <p>And I could supply a complete list of absolute paths for all file names and patterns mentioned in any <code>.gitignore</code>, <code>.hgignore</code>, or <code>svn:ignore</code> property on my disk, but this would be a huge list that would have to be produced by some sort of script.</p>
  
  <p>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?</p>
  
  <p><em>Update</em>: <code>--filter=':- .gitignore'</code> as suggested by LordJavac seems to work as well for Git as <code>--filter=:C</code> does for CVS, at least on the examples I have found, though it is unclear if the syntax is an exact match. <code>--filter=':- .hgignore'</code> does not work very well for Mercurial; e.g. an <code>.hgignore</code> containing a line like <code>^target$</code> (the Mercurial equivalent of Git <code>/target/</code>) is not recognized by rsync as a regular expression. And nothing seems to work for Subversion, for which you would have to parse <code>.svn/dir-prop-base</code> for a 1.6 or earlier working copy, and throw up your hands in dismay for a 1.7 or later working copy.</p>