Archives

Tags

An improved shell script for Svn resetting

A few weeks ago I posted a simple script for resetting an Svn repository to an earlier revision (and recording it as a new revision, so the reset is resettable!).

I decided it was totally shit, and so, I have simplified it a little bit:

  • You no longer have to pass in the URL for the central repository. The script will figure it out for you.
  • The working copy (second) argument is optional. It defaults to the current directory.

Anyway, here it is:

if [ $# = 0 ]
then
  echo "Resets an Svn working copy to an earlier revision."
  echo "svnreset <revision> [PATH...]"
else
  dir=$2
  : ${dir:="."}

  # Find repository URL using AWK.
  repo_url=`svn info $dir | awk '/^URL: (.+)$/ { print $2 }'`

  # Update working copy, merge into older revision, commit with message.
  svn update $dir
  svn merge -rHEAD:$1 $repo_url
  svn commit -m "Reverted back to r$1"
fi

exit 0

Call it like this (with an appropriate revision number): $ svnreset 1242