8

So I'm trying to work on a command to rsync a source folder with a structure like so:

- app.js
- .gitignore
- src/
- src/logs/
- src/logs/.gitignore

The first .gitignore would have a series of files ignored. Typical stuff. The second would look like the following:

*
!.gitignore

This technique is used when you want to check in a directory with none of the files inside. There may also be more .gitignores throughout the directory - this is only one scenario. So my question is this: Is it possible to make rsync interpret all .gitignores relative to the directory they are in?

My initial attempt was the following:

  1. Glob all .gitignores in the directory.
  2. Build command that looks something like:

rsync --exclude-from=.gitignore --exclude-from=src/logs/.gitignore --exclude-from=some/other/folder/.gitignore [source] [destination]

However, this did not work as expected for me. Everything is being ignored because it is reading all of the .gitignore files as if they are at the root. Is there any possible way to do this without having to grep for all .gitignores and create one master file with re-written paths all relative to the root directory?

Thanks!

13

This tells rsync to look in each directory for a file .gitignore:

rsync --filter='dir-merge,-n /.gitignore' [...]

That should do what you want.

The -n after the dir-merge means that (-) the file specifies only excludes and (n) rules are not inherited by subdirectories.

  • This was a great answer. Thank you. I would +1 you if I could. – Jeff Howard Nov 18 '14 at 17:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.