Nic*_*yer 133 svn tortoisesvn ignore
如果我有一个Subversion存储库的工作副本,有没有办法用一个命令或工具删除该工作副本中的所有未版本控制或忽略的文件?基本上,我正在寻找SVN模拟git clean
.
命令行或GUI解决方案(对于TortoiseSVN)都是可以接受的.
Ric*_*sen 131
svn status --no-ignore | grep '^[I?]' | cut -c 9- | while IFS= read -r f; do rm -rf "$f"; done
Run Code Online (Sandbox Code Playgroud)
这具有以下功能:
--xml
选项并解析生成的xml输出之外,除此之外没有太多可以做的事情)svn status
可以在文件名之前打印其他状态字符(它不应该因为文件没有被跟踪,但以防万一...)我使用名为svnclean
包含以下内容的shell脚本:
#!/bin/sh
# make sure this script exits with a non-zero return value if the
# current directory is not in a svn working directory
svn info >/dev/null || exit 1
svn status --no-ignore | grep '^[I?]' | cut -c 9- |
# setting IFS to the empty string ensures that any leading or
# trailing whitespace is not trimmed from the filename
while IFS= read -r f; do
# tell the user which file is being deleted. use printf
# instead of echo because different implementations of echo do
# different things if the arguments begin with hyphens or
# contain backslashes; the behavior of printf is consistent
printf '%s\n' "Deleting ${f}..."
# if rm -rf can't delete the file, something is wrong so bail
rm -rf "${f}" || exit 1
done
Run Code Online (Sandbox Code Playgroud)
Nei*_*eil 109
我知道这是旧的,但万一其他人偶然发现它,svn支持的更新版本(1.9或更高版本)--remove-unversioned
,例如svn cleanup . --remove-unversioned
.
https://subversion.apache.org/docs/release-notes/1.9.html#svn-cleanup-options
Ste*_*fan 97
使用TortoiseSVN:
jkr*_*mer 41
这个oneliner可能会帮助你:
$ svn status | grep '^?' | awk '{print $2}' | xargs rm -rf
Run Code Online (Sandbox Code Playgroud)
小心使用!
小智 15
使用Powershell修改Yanal-Yves Fargialla和gimpf的答案(但不允许对Stackoverflow的原始帖子发表评论):
powershell -Command "&{(svn status --no-ignore) -match '^[\?i]' -replace '^.\s+' | rm -recurse -force}
Run Code Online (Sandbox Code Playgroud)
这会添加克拉("^")以指定行的开头,从而避免匹配包含字母"i"的所有文件.还要将-recurse和-force的标志添加到rm,以使此命令非交互式,因此可以在脚本中使用.
SVN中的许多内容可以通过不同的方式完成,这可以通过这里给出的各种命令行答案来证明.随着版本1.7的出现,TortoiseSVN的另一种技术实际上提供了比Stefan提供的答案更精细的粒度分辨率,让您可以单独从被忽略的文件中选择非版本化文件.只需选择TortoiseSvn >> Clean up...
打开此对话框即可.
使用powershell:
(svn status --no-ignore) -match '[?]' -replace '^.\s+' | rm
Run Code Online (Sandbox Code Playgroud)
从命令行:
powershell -Command "&{(svn status --no-ignore) -match '[?]' -replace '^.\s+' | rm}"
Run Code Online (Sandbox Code Playgroud)
这个oneliner适用于我(基于Richard Hansen的答案,令人惊讶的是它不适用于包含空格的文件):
svn status --no-ignore | grep '^[I?]' | cut -c 9- | xargs -d"\n" -I{} rm {}
Run Code Online (Sandbox Code Playgroud)
使用TortoiseSVN:
这不是一个很好的和干净的解决方案,但我知道的最快的方式(在Windows上).
感谢pkh提示被忽略的文件.