[英]Prepend to subversion checkin template
Command line subversion has the convenient feature of bringing up a checkin "template" of sorts (in the editor specified with the environment variable SVN_EDITOR) upon executing svn ci
: 命令行转换具有方便的功能,可以在执行svn ci
时调出各种签入“模板”(在使用环境变量SVN_EDITOR指定的编辑器中):
(blank line)
--This line, and those below, will be ignored--
M src/myfile.c
A src/otherfile.c
I love this feature because it gives a quick summary of changes to be committed without having to run svn status
and filter through ?
我喜欢这个功能,因为它提供了要提交的更改的快速摘要,而无需运行svn status
和筛选?
results. 结果。
What I'd like to do is grep some stuff from the previous commit's log message and prepend it to the message, like so: 我想做的是从上次提交的日志消息中复制一些内容,并将其添加到消息之前,如下所示:
Some stuff I grepped from the previous log message.
--This line, and those below, will be ignored--
M src/myfile.c
A src/otherfile.c
I've considered creating a script that creates this log message manually by parsing the output of svn status
and then removes it before the actual commit is made, but that seems like it might be overly complex or screw up some other feature of the checkin tool. 我已经考虑过创建一个脚本,该脚本通过解析svn status
的输出来手动创建此日志消息,然后在进行实际提交之前将其删除,但这似乎过于复杂或破坏了签入工具的其他功能。 Is there a better / simpler way? 有没有更好/更简单的方法?
There's a couple ways you could do this. 您可以通过几种方法来做到这一点。 svn ci
takes a commit message as an argument with the -m
flag so you could prepare your message and pass it as a string. svn ci
将提交消息作为带有-m
标志的参数,因此您可以准备消息并将其作为字符串传递。 Something like this: 像这样:
$ svn ci -m "$(svn log | grep Magic\ Text)"
checkin
also takes a filename with -F
, so you could also do something like this: checkin
还使用-F
作为文件名,因此您还可以执行以下操作:
$ svn log | grep Magic\ Text > temp.log
$ svn ci -F temp.log
$ rm temp.log
Or, if you don't want to deal with having a temporary file, passing just -
as the argument to -F
makes checkin
read from stdin
: 或者,如果您不想处理一个临时文件,则只需传递-
作为-F
的参数使checkin
从stdin
读取:
$ svn log | grep Magic\ Text | svn ci -F -
--- EDIT --- -编辑-
It looks like this isn't exactly what you wanted. 看来这并不是您想要的。 If you wanted a way to basically "hook" into the commit and edit the commit message template, this should work for you. 如果您想要一种基本上“钩住”提交并编辑提交消息模板的方法,那么这应该对您有用。 When svn commit
is run, it creates a file called svn-commit.tmp
in the current directory. 运行svn commit
,它将在当前目录中创建一个名为svn-commit.tmp
的文件。 We can override the $SVN_EDITOR
environment variable to use a custom script that edits the svn-commit.tmp
file and then lets us edit it more. 我们可以覆盖$SVN_EDITOR
环境变量以使用自定义脚本来编辑svn-commit.tmp
文件,然后让我们对其进行更多编辑。 Here's what worked for me. 这对我有用。
Create a file somewhere (maybe in $HOME/bin or something) that'll be your new $SVN_EDITOR
. 在某个地方(可能在$ HOME / bin或其他地方)创建一个文件,将其作为新的$SVN_EDITOR
。 Place this inside of it: 将其放入其中:
#!/bin/bash
svn log | grep Whatever > svn-commit2.tmp
cat svn-commit.tmp >> svn-commit2.tmp
mv svn-commit2.tmp svn-commit.tmp
vi svn-commit.tmp
Now in your shell, or in your ~/.bashrc
put the following line: 现在在您的shell或~/.bashrc
放入以下行:
export SVN_EDITOR="$HOME/bin/your_editor.sh"
Make sure to source your bashrc
if you put it in there. 如果将bashrc
放在其中,请确保将其来源。
$ source ~/.bashrc
Now when you do a commit, it should have some extra lines in there. 现在,当您进行提交时,其中应该有一些额外的行。 This is sort of a hacky solution, but it works. 这是一个很棘手的解决方案,但是它可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.