rsync exclude according to .gitignore & .hgignore & svn:ignore like --filter=:C

后端 未结 13 2803
没有蜡笔的小新
没有蜡笔的小新 2020-12-22 17:22

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 ex

13条回答
  •  無奈伤痛
    2020-12-22 17:43

    2018 solution confirmed

    rsync -ah --delete 
        --include .git --exclude-from="$(git -C SRC ls-files \
            --exclude-standard -oi --directory >.git/ignores.tmp && \
            echo .git/ignores.tmp')" \
        SRC DST 
    

    Details: --exclude-from is mandatory instead of --exclude because likely case that exclude list would not be parsed as an argument. Exclude from requires a file and cannot work with pipes.

    Current solution saves the exclude file inside the .git folder in order to assure it will not affect git status while keeping it self contained. If you want you are welcome to use /tmp.

提交回复
热议问题