SVN:设置所有标有“!"的文件到“D"? [英] SVN: set all files marked with "!" to "D"?
问题描述
长话短说,犯了一个错误,现在我在几十个文件夹中至少有一百个文件需要从我的存储库中删除.
long story short, a mistake was made and now I have at least one hundred files throughout dozens of folders that need to be removed from my repository.
现在它们都被标记为!"在 svn status 中,我想删除它们而无需手动输入 svn remove blahblah.
Right now they're all marked as "!" in svn status and I'd like to remove them without manually typing in svn remove blahblah.
有没有快速的方法来做到这一点?
Is there a quick way to do this?
推荐答案
使用 shell-scripting-foo 就很容易做到这一点.
This is pretty easy to do with a little shell-scripting-foo.
svn status | grep "^\!" | awk '{print $2}' | xargs svn del
这是按要求细分的内容:
Here's a breakdown, as requested:
svn status
的输出通过管道传送到grep
grep
管道以!
开头的每一行(正则表达式中的^
表示行的开头,'\' 是必须逃避!
) 的特殊含义awk
然后从grep
获取第二个参数"(可以这么说..这是文件的路径),并仅将其通过管道传输到...xargs
它只是一个用于从标准输入构建执行 shell 命令的实用程序,它生成并运行命令svn del your/file/here
- The output of
svn status
is piped togrep
grep
pipes every line that starts with a!
(The^
in a regex means beginning of line, and the '\' is necessary to escape the special meaning of!
)awk
then takes the second "argument" (so to speak.. this is the path of the file) fromgrep
and pipes only it to...xargs
which is simply a utility for building an executing shell commands from standard input, which generates and runs the commandsvn del your/file/here
你还可以使用这一行的变体来使用 svn
做各种方便的事情,比如递归地向 repo 添加文件:
You can also use variations on this line to do all sorts of handy things with svn
, like recursively adding files to the repo:
svn status | grep "^\?" | awk '{print $2}' | xargs svn add
另外,我只是记得,并想指出如果路径或文件名中有空格,这将不起作用.我总是忘记这一点,因为我从来没有这样做过.如果路径/文件名中有空格,请在第一个示例中使用以下变体:
Also, I just remembered, and wanted to point out that this will not work if you have spaces in your path or filenames. I always forget about that, because I never, ever do. If you have spaces in your paths/filenames, use the following variation on the first example:
svn status | grep "^\!" | sed -e 's/? *//' | sed -e 's/ /\\ /g' | xargs svn del
(可能有更优雅的方式来做到这一点,所以请随意插话).在这个中,第一个 sed
接受第一个空白字符,以及它后面的任何(如果有)空格,并删除它们(基本上是修剪).然后对 sed
的第二次调用用 \
替换任何剩余的空格,就 shell 而言,这是一个转义的空格.想想看,你可能只是用引号包裹起来......
(There's probably a more graceful way to do that, so feel free to chime in). In this one, the first sed
takes the first whitespace character, and any (if any) spaces that follow it, and removes them (basically a trim). Then the second call to sed
replaces any remaining spaces with \
, which is an escaped space, as far as the shell is concerned. Come to think of it, you could probably just wrap it with quotes...
这篇关于SVN:设置所有标有“!"的文件到“D"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!