I want to write a batch file that can auto commit missing file recursively. how to write the batch command? please helps.
5 Answers
Use svn rm $( svn status | sed -e '/^!/!d' -e 's/^!//' )
See http://geryit.com/blog/2011/03/command-line-subversion-practices/ for more command line subversion
The following batch script should SVN delete and commit all files marked as missing (i.e. deleted locally but not using SVN delete):
@echo off
svn status | findstr /R "^!" > missing.list
for /F "tokens=2 delims= " %%A in (missing.list) do (
svn delete %%A && svn -q commit %%A --message "deleting missing files")
Missing files are shown by svn status with the character !, for example:
! test.txt
This script then uses findstr to filter out any modifications other than missing files. This list of missing files is then written to a file, missing.list.
Next, we iterate through this file, using tokens=2 delims= to remove the ! from the lines in the file, leaving us with (hopefully) just the filename. Once we have the filename, we pass it to svn delete and then svn commit. Feel free to change the contents of the message.
Please note that I have not tested this script. In particular, I don't know what happens if one of the files you wish to commit has a space in its path, or what happens if you encounter a conflict part of the way through. It may be better to replace svn delete and svn commit with echo svn delete and echo svn commit, so that you can see what this script is about to do before you let it loose on your repository.
6 Comments
for loop on the output of a command. I seem to remember trying and failing to achieve this before. That's why I wrote the output of the line before the for loop into a file. If you don't want the missing.list file left hanging around, you can always add del missing.list to the end of the batch script.svn st ^| findstr /R "^!") do svn del "%i"for loop on the output of a command. Looks like your batch-fu is better than mine :)just execute the following commands in the root of your working copy:
svn add . --force
svn commit -m"Adding missing files"
1 Comment
Arst,
for /f "usebackq tokens=2*" %i in (svn st ^| findstr /R "^!") do svn del "%i"
is almost right, but you forgot to wrap the parenthesized commands with back ticks:
for /f "usebackq tokens=2*" %i in (`svn st ^| findstr /R "^!"`) do svn del "%i"
Thanks for the concise command, in any case.
merge? Something not yet committed, where you'dadd? Which is it?