Category Archives: Subversion Tips and Tricks


Subversion: How to Recursively UNLOCK files

So you need to unlock files scattered throughout a subversion repository? I did too. Read on to find out how I solved the problem.

At the time we were having power issues, so I don’t know what caused the issue; a power outage at the wrong moment or a buggy client. In any event, when another developer asked me to unlock a file that I hadn’t touched, I quickly investigated and saw that my I had randomly locked 379 files, randomly sprinkled throughout the repository.

The problem is that there is no easy way to fix this from the client side. After taking a moment to think about the horrifying prospect of spending hours of inspecting hundreds of subdirectories to search for locked files I came up with a much more efficient way to go.

First, you need to get a list of status updates:

$ svn status -u

However, this list contains more than just locked files. We need to filter that list down to only locks, and put in into a file:

$ svn st –u | grep "^…..O" > locks.txt

Next, I piped the file to sed and replaced the first two columns and whitespace with the url of the repository. This will build a list of URLs that need to be unlocked, prepended with the repository URL so that the svn unlock command will work.

$ cat locks.txt | \
  sed 's/…..O[ \t]*[0-9]*[ \t]*/http:\/\/server\/svn\/path\/to\/project\//' \
> locked-urls

Finally, you will just need to cobble together a simple bash script to read each line and put it into a variable ($line) and execute “svn unlock $line.”

Within fifteen minutes I was done. Nice.