567

Is there a way to edit the log message of a certain revision in Subversion? I accidentally wrote the wrong filename in my commit message which could be confusing later.

I've seen How do I edit an incorrect commit message in Git?, but the solution to that question doesn't seem to be similar for Subversion (according to svn help commit).

Community
  • 1
  • 1
Paige Ruten
  • 157,734
  • 36
  • 172
  • 191
  • 28
    I was going to upvote this question, but then I realized I already did 4 months ago :) – oksayt Aug 29 '11 at 10:21
  • 6
    If it is code, just make some comments and commit again with the appropriate comments. If you are ok with your comments reflecting the mistake, it is far less effort and much quicker. If not the solution by Kamil Kisiel is clearly the right way to do it. – marty May 10 '12 at 15:15
  • There is an excellent `pre-revprop-change` script that allows the committing user to modify their log for up to 3 hours after the commit. This is an excellent compromise between flexibility / accurate logs, and maintaining the fidelity of the repository: http://www.wandisco.com/svnforum/threads/39203-Pre-revprop-change-shell-script-allows-commiters-to-change-own-log-within-X-hours – jwa May 20 '14 at 14:20
  • if you [can't change the file but still want to add a new commit message](https://stackoverflow.com/a/206856) then you can do `svn propset dummyproperty 1 yourfile; svn commit yourfile -m yourmessage` – mulllhausen Apr 25 '18 at 23:46

10 Answers10

468

Essentially you have to have admin rights (directly or indirectly) to the repository to do this. You can either configure the repository to allow all users to do this, or you can modify the log message directly on the server.

See this part of the Subversion FAQ (emphasis mine):

Log messages are kept in the repository as properties attached to each revision. By default, the log message property (svn:log) cannot be edited once it is committed. That is because changes to revision properties (of which svn:log is one) cause the property's previous value to be permanently discarded, and Subversion tries to prevent you from doing this accidentally. However, there are a couple of ways to get Subversion to change a revision property.

The first way is for the repository administrator to enable revision property modifications. This is done by creating a hook called "pre-revprop-change" (see this section in the Subversion book for more details about how to do this). The "pre-revprop-change" hook has access to the old log message before it is changed, so it can preserve it in some way (for example, by sending an email). Once revision property modifications are enabled, you can change a revision's log message by passing the --revprop switch to svn propedit or svn propset, like either one of these:

$svn propedit -r N --revprop svn:log URL 
$svn propset -r N --revprop svn:log "new log message" URL 

where N is the revision number whose log message you wish to change, and URL is the location of the repository. If you run this command from within a working copy, you can leave off the URL.

The second way of changing a log message is to use svnadmin setlog. This must be done by referring to the repository's location on the filesystem. You cannot modify a remote repository using this command.

$ svnadmin setlog REPOS_PATH -r N FILE

where REPOS_PATH is the repository location, N is the revision number whose log message you wish to change, and FILE is a file containing the new log message. If the "pre-revprop-change" hook is not in place (or you want to bypass the hook script for some reason), you can also use the --bypass-hooks option. However, if you decide to use this option, be very careful. You may be bypassing such things as email notifications of the change, or backup systems that keep track of revision properties.

TheJuice
  • 4,334
  • 2
  • 24
  • 35
Kamil Kisiel
  • 17,767
  • 10
  • 44
  • 54
  • 15
    As of Feb. 3, 2010, the URL is http://subversion.apache.org/faq.html#change-log-msg – GreenMatt Feb 03 '10 at 22:45
  • 1
    Here is a basic implementation for svnadmin option [svn-change-commit](https://github.com/albfan/svn-change-commit) – albfan Jul 08 '15 at 09:33
  • 2
    Thanks! Still useful 6.5 years after the answer. :-) – Michael Aug 25 '17 at 23:18
  • The propedit method more or less worked; however, I couldn't get the log change to reflect in the repo browser. I could only see the updated log in svn command line in Windows. I had to refresh the log cache as a final step: https://stackoverflow.com/questions/25750249/tortoisesvn-edit-log-message-not-displaying – user_007 May 29 '20 at 00:18
91

When you run this command,

svn propedit svn:log --revprop -r NNN 

and just in case you see this message:

DAV request failed; it's possible that the repository's pre-revprop-change hook either failed or is non-existent

Its because Subversion doesn’t allow you to modify log messages because they are unversioned and will be lost permanently.

Unix-hosted SVN

Go to the hooks directory on your Subversion server (replace ~/svn/reponame with the directory of your repository)

cd ~/svn/reponame/hooks

Remove the extension

mv pre-revprop-change.tmpl pre-revprop-change

Make it executable (cannot do chmod +x!)

chmod 755 pre-revprop-change

Source

Windows-hosted SVN

The template files in the hooks directory cannot be used as they are Unix-specific. You need to copy a Windows batch file pre-revprop-change.bat to the hooks directory, e.g. the one provided here.

Robert
  • 650
  • 7
  • 19
Alex. S.
  • 126,349
  • 16
  • 50
  • 61
50

Here's a handy variation that I don't see mentioned in the faq. You can return the current message for editing by specifying a text editor.

svn propedit svn:log --revprop -r N --editor-cmd vim
alex
  • 438,662
  • 188
  • 837
  • 957
mcqwerty
  • 3,306
  • 2
  • 22
  • 24
  • 17
    It does require that the hook has been created - which requires admin rights. `svn: Repository has not been enabled to accept revision propchanges; ask the administrator to create a pre-revprop-change hook` – Matt Jul 05 '12 at 03:26
  • Here is a script to enable the log: http://blog.mmonem.com/enable-changing-svn-log/ – mmonem Jun 15 '14 at 06:40
39
svnadmin setlog /path/to/repository -r revision_number --bypass-hooks message_file.txt
nickf
  • 499,078
  • 194
  • 614
  • 709
  • I'm using Google Code so I don't think I can do it this way, but thanks. – Paige Ruten Nov 20 '08 at 05:19
  • 4
    this worked for me as the propedit method failed with "Repository has not been enabled to accept revision propchanges". thanks! – pfctdayelise May 13 '10 at 23:53
  • 1
    +1 for giving the command directly :-) apache.org was down right now and I couldn't follow any given link... – Rafa Jan 10 '11 at 16:23
  • This answer deserves more points! It is better because you don't have to setup the hook to use it. – Peri Hartman Feb 24 '15 at 17:00
  • 1
    bump for this answer, worked for me without setting up the hook, also didn't change the revision "date/time" in the log, just the message, which was exactly what I was hoping for. – segFaultCoder Nov 17 '16 at 13:23
18

I was recently tasked with this as well.

We wanted to allow our programmers to modify only their own commit messages, and restrict how far back they are allowed to do so. We decided they would be allowed to modify any log messages committed that day, to fix typo's etc.

After looking at a couple other examples online I hacked this together, we are in a windows environment, so this is our contents of pre-revprop-change.bat:

@ECHO OFF

set repos=%1
set rev=%2
set user=%3
set propname=%4
set action=%5

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Only allow changes to svn:log. The author, date and other revision
:: properties cannot be changed
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
if /I not '%propname%'=='svn:log' goto ERROR_PROPNAME

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Only allow modifications to svn:log (no addition/overwrite or deletion)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
if /I not '%action%'=='M' goto ERROR_ACTION

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Only allow user to modify their own log messages
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
set AUTHOR=
for /f "delims=" %%a in ('svnlook author -r %REV% %REPOS%') do @set AUTHOR=%%a

if /I not '%AUTHOR%'=='%user%' goto ERROR_WRONGUSER

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Only allow user to modify log messages from today, old messages locked down
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
set DATESTAMP=
for /f "delims=" %%a in ('svnlook date -r %REV% %REPOS%') do @set DATESTAMP=%%a

for /F "tokens=1-2 delims= " %%a in ("%DATESTAMP%") do (
 set DATESTAMPDATE=%%a
 set DATESTAMPTIME=%%b )

:: Expects DATESTAMPDATE in the format: 2012-02-24
for /F "tokens=1-3 delims=-" %%a in ("%DATESTAMPDATE%") do (
 set DATESTAMPYEAR=%%a
 set DATESTAMPMONTH=%%b
 set DATESTAMPDAY=%%c )

:: Expects date in the format: Thu 08/01/2013
for /F "tokens=1-4 delims=/ " %%a in ("%date%") do (
 set YEAR=%%d
 set MONTH=%%b
 set DAY=%%c )

if /I not '%DATESTAMPYEAR%'=='%YEAR%' goto ERROR_MSGTOOOLD
if /I not '%DATESTAMPMONTH%'=='%MONTH%' goto ERROR_MSGTOOOLD
if /I not '%DATESTAMPDAY%'=='%DAY%' goto ERROR_MSGTOOOLD

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Make sure that the new svn:log message contains some text.
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
set bIsEmpty=true
for /f "tokens=*" %%g in ('find /V ""') do (
 set bIsEmpty=false
)
if '%bIsEmpty%'=='true' goto ERROR_EMPTY

goto :eof

:ERROR_EMPTY
echo Empty svn:log properties are not allowed. >&2
goto ERROR_EXIT

:ERROR_PROPNAME
echo Only changes to svn:log revision properties are allowed. >&2
goto ERROR_EXIT

:ERROR_ACTION
echo Only modifications to svn:log revision properties are allowed. >&2
goto ERROR_EXIT

:ERROR_WRONGUSER
echo You are not allowed to modify other user's log messages. >&2
goto ERROR_EXIT

:ERROR_MSGTOOOLD
echo You are not allowed to modify log messages older than today. >&2
goto ERROR_EXIT

:ERROR_EXIT
exit /b 1 

Edit: Original idea for this came from this thread:

Josh Weatherly
  • 1,628
  • 1
  • 13
  • 27
  • 7
    For some reason, on my system (running Server 2012 and VisualSVN), in the last date check `if /I not '%DATESTAMPDAY%'=='%DAY%' goto ERROR_MSGTOOOLD`, I had to switch to double quotes around the two variables. (You would not believe how long that took to figure out.) Otherwise I would get things like "=='02' is unexpected at this time" (on the 2nd day of the month). My batch-fu is not strong enough to know why that happens, but in case anyone else runs into weird problems, it may help. – Carl Bussema Dec 02 '13 at 20:17
  • @CarlBussema: Thanks for that tidbit. You just saved me a huge headache. – Daniel Szabo Nov 13 '14 at 16:32
  • 1
    Also note that the script above uses american date format, _"Expects date in the format: Thu 08/01/2013"_. So if you do not use that you need to modify that part, in my case the format was "mm.dd.yy", and without the week day. – Zitrax Oct 07 '15 at 14:21
  • That's a cool variation on this nice answer: http://stackoverflow.com/questions/6155/common-types-of-subversion-hooks/68850#68850 – NateJ Jan 15 '16 at 18:09
18

On Windows, using Tortoise SVN client:

  1. right click in your project folder and choose "Show log"
  2. in the Log Messages window, right click on a revision and choose "Edit log message"

If it doesn't work it might because of the way SVN on server is setup, read other responses here.

Andrei N.
  • 2,957
  • 2
  • 31
  • 54
14

If you are using an IDE like eclipse, you can use this easy way.

Right click on the project -> Team - Show history

In that right click on the revision id for your commit and select 'Set commit properties'.

You can modify the message as you want from here.

mani_nz
  • 2,274
  • 2
  • 20
  • 29
  • At least in TortoiseSVN, trying to edit the commit properties for a commit in the commit log fails with the same error message as trying to directly edit the log message. – Christian Severin Aug 18 '14 at 14:31
  • 1
    "DAV request failed; it's possible that the repository's pre-revprop-change hook either failed or is non-existent Repository has not been enabled to accept revision propchanges; ask the administrator to create a pre-revprop-change hook". But as I said: that's using TortoiseSVN (as a non-admin), not Eclipse. Maybe Eclipse hacks the SVN permissions to create that hook, I don't know. – Christian Severin Aug 20 '14 at 16:31
  • Yea maybe. Try doing it in eclipse. – mani_nz Aug 20 '14 at 17:13
  • @ChristianSeverin, I get the same error message when using Eclipse. It surely comes from the Subversion server. – GreenhouseVeg Dec 06 '17 at 17:07
11

If your repository enables setting revision properties via the pre-revprop-change hook you can change log messages much easier.

svn propedit --revprop -r 1234 svn:log url://to/repository

Or in TortoiseSVN, AnkhSVN and probably many other subversion clients by right clicking on a log entry and then 'change log message'.

Ankur Agarwal
  • 19,924
  • 32
  • 117
  • 182
Bert Huijben
  • 19,125
  • 4
  • 54
  • 71
3

The Subversion FAQ covers this, but uses a bunch of confusing undefined terms like REPOS_PATH without giving any actual examples.

It might take a few tries to get it to work, so save your updated commit message in a file. Unlike with svn-commit.tmp files, Subversion won’t preserve your typing if there’s a problem.

In your working directory, run

svn propedit -r N --revprop svn:log

to edit the commit message. If that works, great! But it probably won’t, because the svn:log revision property is unversioned and Subversion by default will stop you from overwriting it, either with the hook script pre-revprop-change, or an error message that you don’t have such a hook.

To change the hooks, you need access to the filesystem on which the repository is hosted. svn info will tell you the Repository Root. Suppose it’s ~/svnrepo.

  1. cd to ~/svnrepo/hooks
  2. Is there a pre-revprop-change or pre-revprop-change.bat script? If so, temporarily comment out the part of it that aborts if you try to change svn:log.
  3. Otherwise, on Windows, create a blank file called pre-revprop-change.bat. Here’s one way to do that:

    copy con pre-revprop-change.bat
    ^Z
    
  4. Otherwise, on Unix, run

    echo '#!/bin/sh' > pre-revprop-change
    chmod +x pre-revprop-change
    
  5. In the working copy, run svn propedit -r N --revprop svn:log again

  6. Undo your changes to ~/svnrepo/hooks/svn-revprop-change(.bat)
andrewdotn
  • 27,806
  • 6
  • 80
  • 110
1

I found a nice implementation of the server side pre-rev-prop-change hook at the svnforum: https://www.svnforum.org/forum/opensource-subversion-forums/scripts-contributions/8571-pre-revprop-change-shell-script-allows-commiters-to-change-own-log-within-x-hours

It implements

  • user checking, that is only own commit messages can be edited.
  • Svn admin override; admin can edit anything.
  • time stamp comparison: only commits that are younger than certain time can be edited

Grab it from there and edit at will. I'd rather not copy it here since I am not the original author and there is no copyright notice that would allow me to do it.

teroi
  • 1,057
  • 11
  • 18