Automatically remove Subversion unversioned files

前端 未结 30 3114
感情败类
感情败类 2020-11-28 18:54

Does anybody know a way to recursively remove all files in a working copy that are not under version control? (I need this to get more reliable results in my automatic build

30条回答
  •  借酒劲吻你
    2020-11-28 18:58

    svn st --no-ignore  | grep '^[?I]' | sed 's/^[?I]  *//' | xargs -r -d '\n' rm -r
    

    This is a unix shell command to delete all files not under subversion control.

    Notes:

    • the st in svn st is an build-in alias for status, i.e. the command is equivalent to svn status
    • --no-ignore also includes non-repository files in the status output, otherwise ignores via mechanisms like .cvsignore etc. - since the goal is to have a clean starting point for builds this switch is a must
    • the grep filters the output such that only files unknown to subversion are left - the lines beginning with ? list files unknown to subversion that would be ignored without the --no-ignore option
    • the prefix up to the filename is remove via sed
    • the xargs command is instructed via -r to not execute rm, when the argument list would be empty
    • the -d '\n' option tells xargs to use a newline as delimiter such the command also works for filenames with spaces
    • rm -r is used in case complete directories (that are not part of the repository) need to be removed

提交回复
热议问题