5

I want to write a batch file that can auto commit missing file recursively. how to write the batch command? please helps.

3
  • What's a missing file? Something from another branch, where you'd merge? Something not yet committed, where you'd add? Which is it? Commented Feb 18, 2011 at 10:33
  • The linked image shows the files that I delete from local, but I want to commit it to SVN throught command line. badongo.com/pic/11740167 Commented Feb 18, 2011 at 11:01
  • 2
    @Linus: missing files are those that have been deleted locally but not using SVN delete. @Arst: are you looking for a script that will SVN delete and then SVN commit all missing files? Could you not SVN delete files instead of locally deleting them? Commented Feb 18, 2011 at 11:12

5 Answers 5

11

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

Sign up to request clarification or add additional context in comments.

2 Comments

Anyone know.. what is sed?
it's a Unix command, this will not work on Windows unless you use Cygwin
8

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

thx for the answer. Is that possible to don't write into file?
I'm not sure if it you can use a 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.
for /f "usebackq tokens=2*" %i in (svn st ^| findstr /R "^!") do svn del "%i"
Accoring to ur post, I modified it as above.
@Arst: that does indeed seem to be how you run a for loop on the output of a command. Looks like your batch-fu is better than mine :)
|
0

just execute the following commands in the root of your working copy:

    svn add . --force
    svn commit -m"Adding missing files"

1 Comment

This adds new files but doesn't 'delete' files from SVN that have been removed from the working copy.
0

I made little change for my work..

@echo off

cd c:\project

for /f "usebackq tokens=2*" %%i in (\`svn st ^| findstr /R "^!"\`) do svn del "%%i %%j" 

then

svn commit . -m test 

It works for me. Thanks.

Comments

0

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.

1 Comment

@stevek_mcc Good catch. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.