Change author of SVN commit

What can you do when for some reason you have the wrong author in your SVN commit?  You might think this is something that should never happen, but what if it did? There is a solution.

The good news is that this solution is not a bad hack into the deep, dark core of SVN. It is supported by SVN with one of the already included hooks. When you create an SVN repository, a complete directory structure is created for it. This directory structure contains all the revisions of the repository as well as the configuration and the hooks.

Advertisements
repository_name/
|-- conf
|-- db
|-- format
|-- hooks
\-- locks

The hooks directory in a new repository contains a number of hooks which are not enabled. One of them is called “pre-revprop-change” which we will use to change the author. SVN suports more then just changing the author.

The hook itself does not provide the functionality to change the commit properties. It is more a controlling instance to allow or deny it. As mentioned, all the hooks are disabled by default. To enable the “pre-revprop-change” hook we have to go to the “hooks” directory and rename the file “pre-revprop-change.tmpl” to “pre-revprop-change”. We also have to make sure that this file is executable to enable the hook.

By default the hook only allows changing of the property svn:log, so you need to modify the hook or instead generate a hook file with the following content. The hook itself is a small shell script that should return the exit code “0” to allow the change operation, or anything else to deny it.

exit 0

When the line “exit 0” is placed at the beginning of the existing script or alone in a separate one, the hook will allow all property changes to the SVN repository. Now to change the author of a specific revision, execute the following command where “revision_number” is the revision that you want to change the author for and “new_username” is the new author/username you want to set.

svn propset --revprop -r <revision_number> svn:author <new_username>

Other propertied can be changed in the same way. For example, the commit message with with this command:

svn propset --revprop -r <revision_number> svn:log <new_commit_message>

I used this as a temporary solution to fix a problem that occurred during migration. To avoid any unwanted changes I disabled the hook again after I corrected the author.

If you want to know more about the hooks and the possibilities to change revision properties, have a look at the free Subversion book.


Read more of my posts on my blog at http://blog.tinned-software.net/.

This entry was posted in Version control system and tagged , , . Bookmark the permalink.