How do I exclude certain files from a svn diff?

三世轮回 提交于 2019-11-30 02:54:44

问题


I'm using svn diff -c 789 to show the changes made in revision 789 of our software, but it's showing a lot of files I don't care about, in particular test files. How can I exclude certain files from the diff, for example all files which match the pattern *Test.java?

I'm using Cygwin on Windows, if that's important.


回答1:


As svn diff does not allow to exclude specific files from the output, below is a BASH script that can be used to achieve that.

It takes two arguments:

  • file with an svn diff output
  • pattern of the files to be excluded (e.g. test/*)

and prints the content of the file without the changes from the files matching pattern.

#!/bin/bash

test $# -ne 2 && echo "Usage: $0 svn_diff_file exclude_pattern" && exit 1

ignore=0
while IFS= read -r line; do
    echo $line | grep -q -e "^Index: " && ignore=0
    echo $line | grep -e "^Index: " | grep -q -e "^Index: $2" && ignore=1
    test $ignore -eq 0 && echo "$line"
done < $1

Update

I just came across a tool that does this job: filterdiff. It's usage is very similar to the above script:

filterdiff svn_diff_file -x exclude_pattern




回答2:


By the way, remember that the svn diff commands works as others commands following the in Unix modular philosophy where each command has a standard input and ouput. You can genare your own customize script for listing files you want to include redirect the output of that script to the svn diff commands via the use of pipes and then redirect your output of diff to the desired file you want to create. Just to be more clear : follow this example

svn diff `cat change_list.txt` > patch.diff

in change_list.txt the are the files you want to include in the diff separated by space. For example, the content of the file could be this :

"domain/model/entity.java"

"web_app/controllers/controller.java"

So following this approach, the only dificult of your problem is reduced to implement a script that like Adam generously wrote above.

Hope it helps!

Vic.




回答3:


This is what I did:

FILES=$(svn status some_dir|grep ^M|cut -b2-|grep -v dir_to_remove)
test -n "$FILES" && svn diff "$FILES"


来源:https://stackoverflow.com/questions/16414954/how-do-i-exclude-certain-files-from-a-svn-diff

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