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

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


当前回答

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

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

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

其他回答

在Windows操作系统下,使用Tortoise SVN客户端:

右键单击项目文件夹,选择“显示日志” 在日志消息窗口中,右键单击修订并选择“编辑日志消息”。

如果它不起作用,可能是由于SVN在服务器上的设置方式,请在这里阅读其他响应。

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

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

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

请看这部分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.

我在svnforum上找到了一个很好的服务器端pre-rev-prop-change钩子的实现: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

它实现了

用户检查,即只有自己提交的消息可以编辑。 Svn管理员覆盖;管理员可以编辑任何东西。 时间戳比较:只有小于特定时间的提交才能被编辑

从那里获取并随意编辑。我不想在这里复制它,因为我不是原作者,也没有版权声明允许我这样做。

Subversion常见问题解答涵盖了这一点,但使用了一堆令人困惑的未定义术语,如REPOS_PATH,而没有给出任何实际示例。

可能需要尝试几次才能使其工作,因此将更新后的提交消息保存在一个文件中。与svn-commit.tmp文件不同,如果出现问题,Subversion将不会保留您的输入。

在工作目录中运行

svn propedit -r N——revprop svn:log

编辑提交消息。如果有效,那太好了!但它可能不会,因为svn:log revision属性是unversioned的,Subversion默认情况下会阻止您覆盖它,要么使用钩子脚本pre-revprop-change,要么使用错误消息告诉您没有这样的钩子。

要更改钩子,您需要访问存储库所在的文件系统。svn info会告诉你存储库根目录。假设是~/svnrepo。

cd to ~/svnrepo/hooks 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. 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 Otherwise, on Unix, run echo '#!/bin/sh' > pre-revprop-change chmod +x pre-revprop-change In the working copy, run svn propedit -r N --revprop svn:log again Undo your changes to ~/svnrepo/hooks/svn-revprop-change(.bat)