简体   繁体   English

svn可以“忽略”已删除的文件或从存储库中删除它们吗?

[英]Can svn “ignore” deleted files or delete them from repository?

When I try to commit my project to svn I get the following issue 当我尝试将我的项目提交给svn时,我遇到了以下问题

svn: '/var/www/sites/blabla/425/file.png' is scheduled for addition, but is missing

This happens because some material is deleted from the project (and I cannot use svn to delete it). 发生这种情况是因为从项目中删除了一些材料(我不能使用svn来删除它)。 Is there a way to say svn to ignore such files, or just to delete it them if they are not found ? 有没有办法说svn忽略这些文件,或只是删除它们如果找不到它们?

When you do a svn status , the output will show any such files which are "missing" as a line starting with an exclamation mark: 当您执行svn status ,输出将显示任何此类文件“缺少”作为以感叹号开头的行:

!       425/file.png

You should write a script (in your scripting language or command line shell of choice) which parses this output, looks for lines starting with an exclamation mark, extracts the filename, and which then does a svn revert <filename> . 您应该编写一个脚本(使用您选择的脚本语言或命令行shell)来解析此输出,查找以感叹号开头的行,提取文件名,然后执行svn revert <filename> This will then undo the local change to that file, allowing you to commit without problems. 然后,这将撤消对该文件的本地更改,从而允许您毫无问题地进行提交。

edit : since you mentioned a php script in a comment, I suppose you are familiar with PHP scripting. 编辑 :既然你在评论中提到了php脚本,我想你熟悉PHP脚本。 In that case you can make use of the PHP function svn_status . 在这种情况下,您可以使用PHP函数svn_status

edit2 : if you want to delete the file from the repository, do a svn rm --force <filename> instead. edit2 :如果要从存储库中删除文件,请改为使用svn rm --force <filename>

So you svn add the file but later on deleted it manually? 所以你svn add文件但稍后手动删除它? Try; 尝试;

svn rm --force file.png

to remove it from the SVN index. 从SVN索引中删除它。

从终端运行以下命令:

svn revert $(svn st | awk 'BEGIN{FS=""} $1=="!" && $2 !~ /\.(sql|log|tmpl)$/ {print $2}')

Works for me: 适合我:

svn status | grep ^\! | awk '{print $2}' | xargs -L1 svn del --force

and if you have whitespaces in your filenames, we cannot use awk so we cut until the start of the filename (You'll probably have to edit this one: because idk if we must cut 9 characters on every system) : 如果你的文件名中有空格,我们就不能使用awk,所以我们剪切到文件名的开头(你可能要编辑这个:因为idk如果我们必须在每个系统上剪掉9个字符):

svn status | grep ^\! | cut -c9- | sed 's/ /\\ /g'| xargs -L1 svn del --force

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM