How can I release locks in Subversion recursively?

Version ControlLockingSvn

Version Control Problem Overview


I am having a problem with version control in Subversion. I checked out a working copy from respository and got locks on all of its files. Then, without releasing the locks I have deleted the folder from disk.

  • I can't delete the folder from repository, since its got a lock
  • If the I and try to release the locks recursively, it says there are no locks to be released.
  • In Browse Repository view, I can only break the locks on particular, not folders recursively.

How can I break the locks residing in repository? I am using TortoiseSVN on Windows. Is there a command to break locks recursively for a folder?

Version Control Solutions


Solution 1 - Version Control

Ok I got it. Here's what worked for me.

  • Check out a working copy
  • Then go in Windows explorer menu, TortoiseSVN -> Check for modifications...
  • Click on Check repository button
  • Select All the files, right click and select the break lock option
  • Delete the working copy and the one in repository. Voila! :)

Solution 2 - Version Control

Doing an SVN cleanup will release the lock as well:

$ svn cleanup

Solution 3 - Version Control

From the [advance locking section][1]

$ svn status -u
M              23   bar.c
M    O         32   raisin.jpg
       *       72   foo.h
Status against revision:     105
$ svn unlock raisin.jpg
svn: 'raisin.jpg' is not locked in this working copy

That simply means the file is not locked in your current working directory , but if it is still locked at the repository level, you can force the unlock ("breaking the lock")

$ svn unlock http://svn.example.com/repos/project/raisin.jpg
svn: Unlock request failed: 403 Forbidden (http://svn.example.com)
$ svn unlock --force http://svn.example.com/repos/project/raisin.jpg
'raisin.jpg' unlocked.

(which is what you did through the TortoiseSVN GUI) [1]: http://svnbook.red-bean.com/nightly/en/svn.advanced.locking.html

Solution 4 - Version Control

If somebody else has locked the files remotely, I found that using TortoiseSVN 1.7.11 to do the following successfully unlocked them in my working copy. (similar to vikkun's answer)

  • Right click working copy > Check for modifications
  • Click Check repository button
  • Select files you wish to unlock
  • Right click > Get lock
  • Check "Steal the lock" checkbox
  • After lock is stolen, select again
  • Right click > Release lock

Files in working copy should now be unlocked.

Solution 5 - Version Control

Unless you have admin access to the svn machine and can use the 'svnadmin' tool, your best option seems to be this:

  1. Checkout the problematic directory using svn checkout --ignore-externals *your_repo*
  2. Use svn status --show-updates on the checked out repository to find out which files are potentially locked (if someone finds the documentation on the meaning of the status codes please comment).
  3. Use svn unlock --force *some_file* on the files found at 2.

I've used the following one-liner to automate 2. and 3.:

svn status -u | head -n -1 | awk '{ print $3 }' | xargs svn unlock --force

Solution 6 - Version Control

If you have access to the svnadmin tool in the repo server, you can use this alternative to remove all locks (based on the script posted by VonC)

svnadmin lslocks <path_to_repo> |grep -B2 Owner |grep Path |sed "s/Path: \///" | xargs svnadmin rmlocks <path_to_repo>

Solution 7 - Version Control

The repository administrator can remove the locks (recursively), operating on hundreds of files inside a problematic directory -- but only by scripting since there is not a --recursive option to svnadmin rmlocks.

$repopath=/var/svn/repos/myproject/;
$problemdirectory=trunk/bikeshed/
IFS=$'\n'; for f in $(sudo svnadmin lslocks $repopath $problemdirectory \
| grep 'Path: ' \
| sed "s/Path: \///") ; \
do sudo svnadmin rmlocks $repopath "$f" ; done

This solution works with filenames that have spaces in them.

Solution 8 - Version Control

For me deleting the lock file inside .svn did not work since I got bad checksum msg after trying to update the file.

I got the following msg after executing svn cleanup inside the directory:

svn: In directory '' svn: Can't copy '.svn/tmp/text-base/file_name.svn-base' to 'filename.3.tmp': No such file or directory

So I copied my file to .svn/tmp/text-base and changed the name to file_name.svn-base. Then cleanup and update worked fine.

Solution 9 - Version Control

When I tried to run the script from above as originally provided, I was getting an error when it tried to set the variables: ./scriptname: line1: =/svn/repo/path/: No such file or directory ./scriptname: line2: =directory/: No such file or directory

I removed the '$' from the first two lines and this worked perfectly after that.

repopath=/var/svn/repos/myproject/;
problemdirectory=trunk/bikeshed/
IFS=$'\n'; for f in $(sudo svnadmin lslocks $repopath $problemdirectory \
| grep 'Path: ' \
| sed "s/Path: \///") ; \
do sudo svnadmin rmlocks $repopath "$f" ; done

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionvikmalhotraView Question on Stackoverflow
Solution 1 - Version ControlvikmalhotraView Answer on Stackoverflow
Solution 2 - Version ControlrgubbyView Answer on Stackoverflow
Solution 3 - Version ControlVonCView Answer on Stackoverflow
Solution 4 - Version ControlDanView Answer on Stackoverflow
Solution 5 - Version ControlApteryxView Answer on Stackoverflow
Solution 6 - Version ControlGustavo CiprianiView Answer on Stackoverflow
Solution 7 - Version ControlGreg RundlettView Answer on Stackoverflow
Solution 8 - Version ControlGregView Answer on Stackoverflow
Solution 9 - Version ControlEricMGView Answer on Stackoverflow