Convert .gitignore to rsync merge filter include file? (with sed or awk)

I tried using rsync --filter=':+ .gitignore' ( - / exclude works, but doesn't include ), but to no avail.

Basically, I just want to include the .ignore file in the script and download everything in it using rsync to the remote computer.

If anyone had sed or awk .gitignore skills in a file suitable for include with --filter='merge file' etc., I really liked it!

Or, alternatively, just to let rsync understand .gitignore to enable.

https://www.kernel.org/pub/software/scm/git/docs/gitignore.html 'PATTERN FORMAT'

http://linux.die.net/man/3/fnmatch

https://git.samba.org/?p=rsync.git;a=blob_plain;f=wildtest.txt;hb=HEAD

https://git.samba.org/?p=rsync.git;a=blob_plain;f=wildtest.c;hb=HEAD

Some problems in rsync bla/ mean that only dir, bla/* means only the files in this directory, bla/** means only everything under this dir (including subdirs) and bla/*** , finally means bla and all this content, but all git may have bla/

But exclude rules seem compatible.

+4
source share
3 answers

Maybe something like this: (Again, untested)

 git ls-files -oz | rsync --include-from=- --from0 
+2
source

I recommend using gsync rather than rsync . I wrote it because:

I have a project with the following characteristics:

  • .gitignore in the root directory lasts 60+ lines
  • There are 4 subdirectories with your .gitignore
  • Some .gitignore files contain lines with exceptions ! -style

I tried the methods in other answers. Some of them were promising, but I ended up in the discarding over-long filter error. So I wrote gsync as a wrapper script for rsync to properly handle .gitignore files (in sub-folders, with support for ! -Style exceptions. I think you will find this useful.

+1
source

Consider this: (untested)

 rsync --include=.gitignore 

This is what the man page says, although the git ignore file is a bit more advanced, giving you the ability to comment out lines and β€œignore ignored files” that this command does not comply with.

How complex is your .gitignore file, and most importantly ... does it ignore the .gitignore file?

-1
source

Source: https://habr.com/ru/post/1482872/


All Articles