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

后端 未结 13 2800
没有蜡笔的小新
没有蜡笔的小新 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

    After the hours of research I have found exactly what I need: to sync destination folder with the source folder (also deleting files in the destination if they were deleted in the source), and not to copy to the destination the files that are ignored by .gitignore, but also not to delete this files in the destination:

    rsync -vhra /source/project/ /destination/project/ --include='**.gitignore' --exclude='/.git' --filter=':- .gitignore' --delete-after
    

    Another words, this command completely ignore files from .gitignore, both in source and in the destination. You can omit --exclude='/.git' part if want to copy the .git folder too.

    You MUST to copy .gitignore files from the source. If you will use LordJavac's command, the .gitignore will not be copied. And if you create a file in the destination folder, that should be ignored by .gitignore, this file will be deleted despite .gitignore. This is because you don't have .gitignore-files in the destination. But if you will have this files, the files described in the .gitignore will not be deleted, they will be ignored, just expected.

提交回复
热议问题