是否有一种方法可以在Subversion中编辑某个修订的日志消息?我不小心在我的提交消息中写了错误的文件名,这可能会让人困惑。
我已经看到如何在Git中编辑错误的提交消息?,但这个问题的解决方案似乎与Subversion不同(根据svn help commit)。
是否有一种方法可以在Subversion中编辑某个修订的日志消息?我不小心在我的提交消息中写了错误的文件名,这可能会让人困惑。
我已经看到如何在Git中编辑错误的提交消息?,但这个问题的解决方案似乎与Subversion不同(根据svn help commit)。
当前回答
我最近也接到了这个任务。
我们希望允许我们的程序员只修改他们自己的提交消息,并限制他们允许这样做的时间。我们决定允许他们修改当天提交的任何日志消息,以修复错字等。
在网上看了几个其他的例子后,我把它放在一起,我们在一个windows环境中,所以这是我们的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
编辑:最初的想法来自这个帖子:
其他回答
如果您的存储库允许通过pre-revprop-change钩子设置修订属性,您可以更容易地更改日志消息。
svn propedit --revprop -r 1234 svn:log url://to/repository
或者在TortoiseSVN, AnkhSVN和许多其他subversion客户端中,右键单击日志条目,然后“更改日志消息”。
svnadmin setlog /path/to/repository -r revision_number --bypass-hooks message_file.txt
在Windows操作系统下,使用Tortoise SVN客户端:
右键单击项目文件夹,选择“显示日志” 在日志消息窗口中,右键单击修订并选择“编辑日志消息”。
如果它不起作用,可能是由于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)
我的预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的例子