Cygwin diff won't exclude files if a directory is included in the pattern

做~自己de王妃 提交于 2020-01-15 15:36:06

问题


I need to do a recursive diff using cygwin that needs do exclude all .xml files from certain directories, but not from other directories. According to the --help option I should be able to do this with with the --exclude=PAT option where PAT is a pattern describing the files I want to exclude from the diff.

If I do this:

diff -rw --exclude="classes/Services.xml" 

the diff does not ignore the Services.xml file in the classes directory. If I do this

diff -rw --exclude="Services.xml"

the diff does ignore the Services.xml file in all directories.

I need to do something like this:

diff -rw --exclude="*/generated/resources/client/*.xml"

to ignore all .xml files in the directory */generated/resources/client/.

Whenever I add path information to the --exclude pattern cygwin does not ignore the file(s) I've specified in the pattern.

Is there some way to make cygwin diff recognize a pattern that identifies certain files in certain directories? It seems to not be able to handle any directory information at all.


回答1:


I ended up having to write a Java utility that walks the directory tree, excluding certain directories, and calls diff on each level.




回答2:


Use find with an approprite expression. Assuming your trees are in tree1/ and tree2/, then

$ find tree1 -type f ! -path '*classes/Services.xml' |
    while read f; do diff -rw "$f" "tree2${f#tree1}"; done

Hmmm, as it stands this misses files in tree2/ that do not exist in tree1/.



来源:https://stackoverflow.com/questions/4619075/cygwin-diff-wont-exclude-files-if-a-directory-is-included-in-the-pattern

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!