是否有一种方法可以在Subversion中编辑某个修订的日志消息?我不小心在我的提交消息中写了错误的文件名,这可能会让人困惑。

我已经看到如何在Git中编辑错误的提交消息?,但这个问题的解决方案似乎与Subversion不同(根据svn help commit)。


当前回答

实际上,您必须拥有存储库的管理权限(直接或间接)才能做到这一点。您可以配置存储库以允许所有用户执行此操作,也可以直接在服务器上修改日志消息。

请看这部分Subversion常见问题解答(重点是我的):

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.

其他回答

执行此命令时,

svn propedit svn:log --revprop -r NNN 

以防你看到这条信息

DAV请求失败;有可能 存储库的pre-revprop-change 钩子要么失败,要么不存在

这是因为Subversion不允许您修改日志消息,因为它们是未版本化的,并且将永久丢失。

Unix-hosted SVN

转到Subversion服务器上的hooks目录(将~/svn/reponame替换为存储库的目录)

cd ~/svn/reponame/hooks

删除扩展名

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

让它可执行(不能做chmod +x!)

chmod 755 pre-revprop-change

Windows-hosted SVN

hooks目录中的模板文件不能使用,因为它们是特定于unix的。您需要复制一个Windows批处理文件pre-revprop-change.bat到hooks目录,例如这里提供的目录。

这里有一个方便的变化,我没有看到在常见问题中提到。可以通过指定文本编辑器返回当前消息进行编辑。

svn propedit svn:log --revprop -r N --editor-cmd vim

我的预revprop-change批处理脚本版本,具有独立于地区的时间比较。我在这里使用了一个PowerShell调用,它在某些情况下似乎会闪烁一个窗口,并增加了明显的延迟。

@ECHO OFF

set reposPath=%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% %reposPath%') 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 minDate=
set revDate=
set revDateStr=
for /f "delims=" %%a in ('svnlook date -r %rev% %reposPath%') do set revDateStr=%%a

:: Expects revDateStr in the format: 2012-02-24 ...
:: https://svnbook.red-bean.com/en/1.7/svn.ref.svnlook.c.date.html
for /F "tokens=1-3 delims=- " %%a in ("%revDateStr%") do set revDate=%%a%%b%%c
:: Note that PowerShell calls like this can be slow and a window can show up while they run.
for /f %%i in ('"powershell (Get-Date).AddDays(-1).ToString(\"yyyyMMdd\")"') do set minDate=%%i
if "%revDate%" LSS "%minDate%" 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 that are too old (2+ days). >&2
goto ERROR_EXIT

:ERROR_EXIT
exit /b 1

来源: 原稿,之前的答案, PowerShell的例子

如果您正在使用eclipse之类的IDE,则可以使用这种简单的方法。

Right click on the project -> Team - Show history

右键单击提交的修订id,并选择“设置提交属性”。

您可以从这里修改您想要的消息。

如果您的存储库允许通过pre-revprop-change钩子设置修订属性,您可以更容易地更改日志消息。

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

或者在TortoiseSVN, AnkhSVN和许多其他subversion客户端中,右键单击日志条目,然后“更改日志消息”。