How to remove all deleted files from repository?

守給你的承諾、 提交于 2019-12-20 08:00:36

问题


I have a script in which I add all new files before to commit my working copy to my repository with this line:

svn status | grep ^\? | awk '{print $2}' | xargs svn add

I now want to add a line that delete from repository all deleted files in my working copy. In other terms, I cannot specify them one by one, and I need to detect them with svn status and then automatically remove them. However the line doesn't work.

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

As you can see I've replaced

"?" with "!" and

"add" with "--force delete"

Could you tell me why it doesn't work ?

ps. I know it is a risky procedure. I've already discussed all about it. thanks

thanks


回答1:


I just tried this and it works perfectly.

$ svn st | grep '^!' | awk '{print $2}' | xargs svn delete --force
D         groups.pl
D         textblock.pl

Do your files have spaces in their names?

WAIT A SECOND!! I see the problem. You have:

svn --force delete

and not:

svn delete --force

The --force is a parameter of the delete command and not the svn command.




回答2:


I have found another solution, too.

svn status | grep '^\!' | sed 's/! *//' | xargs -I% svn rm %

I have seen it on http://donunix.blogspot.de/2009/02/svn-remove-all-deleted-files.html




回答3:


svn status | grep '^!' | sed 's/! *//' | xargs -d '\n' svn delete --force

The solution works for filenames with spaces and special characters.

  • svn status - lists all changes, deleted files are marked as !
  • grep '^!' - extracts lines that begins with ! (i.e. deleted files)
  • sed 's/! *//' - removes !-char at the beginning and spaces after it
  • xargs -d '\n' - treats every input line (including spaces and special characters) as separate argument and passes them to svn delete --force



回答4:


what about adding you could simply use

svn add --force .

or

svn --force add .

it would do the same: add all unversioned files except ones matching svn:ignore patterns




回答5:


an approach using a perl oneliner would be:

svn st | perl -ne 'print "$1\n" if /^\!\s+(.*)/' | xargs svn rm

this should also work with space characters in file names.

edit: improved regexp



来源:https://stackoverflow.com/questions/4608798/how-to-remove-all-deleted-files-from-repository

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