rsync 只有两个字典

Rsync only two dictionaries

我想在本地处理一些我想测试的程序,运行 在远程服务器上。我正在编辑的唯一文件是 srcinclude 目录中的 *.hpp*.cpp

为此,我尝试了这个 rsync 命令,只上传必要的源文件:

rsync --dry-run -av --exclude '*' --include 'src/*.cpp' --include 'include/*.hpp' Programm/ user@remote:/home/user/Programm

但由于某些原因,在进行一些本地更改后没有文件提交到服务器。

感谢任何提示!

谢谢

这是 rsync 手册页的摘录,可以解决您的确切问题。

Note that, when using the --recursive (-r) option (which is implied by -a), every subdir component of every path is visited left to right, with each directory having a chance for exclusion before its content. In this way include/exclude patterns are applied recursively to the pathname of each node in the filesystem's tree (those inside the transfer). The exclude patterns short-circuit the directory traversal stage as rsync finds the files to send.

For instance, to include "/foo/bar/baz", the directories "/foo" and "/foo/bar" must not be excluded. Excluding one of those parent directories prevents the examination of its content, cutting off rsync's recursion into those paths and rendering the include for "/foo/bar/baz" ineffectual (since rsync can't match something it never sees in the cut-off section of the directory hierarchy).

The concept path exclusion is particularly important when using a trailing '*' rule. For instance, this won't work:

+ /some/path/this-file-will-not-be-found
+ /file-is-included
- *

This fails because the parent directory "some" is excluded by the '*' rule, so rsync never visits any of the files in the "some" or "some/path" directories. One solution is to ask for all directories in the hierarchy to be included by using a single rule: "+ */" (put it somewhere before the "- *" rule), and perhaps use the --prune-empty-dirs option. Another solution is to add specific include rules for all the parent dirs that need to be visited. For instance, this set of rules works fine:

+ /some/
+ /some/path/
+ /some/path/this-file-is-found
+ /file-also-included
- *