如何在 Unison 同步中忽略文件夹及其子目录

如何在 Unison 同步中忽略文件夹及其子目录

我用齐奏为了在我的机器之间同步网站项目,在我的其中一台机器上,我想避免同步(双向)我监视的文件夹中包含的一些文件夹:

/vendor
/node_modules
/storage/debugbar
/staroge/framework

这是我用来执行同步的 .prf 文件的配置文件,您可以看到文件夹位于忽略路径行中。

# Roots of the synchronization
root = /Volumes/Data HD
root = ssh://Server//volume1/My Files

# Paths
path = Sites

# Some regexps specifying names and paths to ignore
ignore = Name */@eaDir
ignore = Name */_notes
ignore = Name .DS_Store
ignore = Name SyncToy_*.dat
ignore = Path */Archives
ignore = Path */tools
ignore = Name *.sublime*

# Ignore laravel composer and npm folders
ignore = Path {Sites/CRMJobs/node_modules}
ignore = Path {Sites/Loot/node_modules}
ignore = Path {Sites/Pompous/node_modules}
ignore = Path */vendor
ignore = Path */node_modules
ignore = Path */storage/debugbar
ignore = Path */storage/framework

log = true
times = true
auto = true

您可以看到,在某些情况下,我甚至明确提到要忽略的完整补丁,但它们仍然是同步的。

有人能告诉我我做错了什么吗?

答案1

看到这个路径指定上的位在 Unison 手册中。Path您应该使用而不是Name

ignore = Name vendor
ignore = Name node_modules
ignore = Name storage/debugbar
ignore = Name storage/framework

答案2

我使用了一个大的忽略正则表达式来执行此操作,因为所有其他方法都不起作用。如果 unison 支持负向前看,这会变得非常简单,但我不得不使用如下所述的通过负字符类进行模拟:

https://clusterise.com/articles/regex-negative-lookahead/

如果我只想要包含 2 个子文件夹(例如“abc”和“def”),我会使用以下命令:

Regex ^([^ad].*|a[^b].*|ab[^c].*|d[^e].*|de[^f].*)

哪种方式模拟负面前瞻^(?!abc|def)

相关内容