一种方式是通过使用脚本,该GIT_EDITOR
环境变量和dcommit
--edit
选项。
将下列内容保存到一个文件,姑且称之为svnmessage.sh
:
#!/bin/sh
c=`git rev-parse HEAD`
t=`git cat-file -t $c`
m=`cat "$1"`
if [ "commit" = "$t" ]; then
o=`git cat-file $t $c`
o_a=`echo "$o" | grep '^author '`
o_c=`echo "$o" | grep '^committer '`
author=`echo "$o_a" | sed -e 's/^author \(.*>\).*$/\1/'`
authorts=`echo "$o_a" | sed -e 's/^author .*> \([0-9]\+\) .*$/\1/'`
authordt=`date -d @$authorts +"%Y-%m-%d %H:%M:%S %z"`
committer=`echo "$o_c" | sed -e 's/^committer \(.*>\).*$/\1/'`
committerts=`echo "$o_c" | sed -e 's/^committer .*> \([0-9]\+\) .*$/\1/'`
committerdt=`date -d @$committerts +"%Y-%m-%d %H:%M:%S %z"`
m="$m
-----
Author: $author $authordt
Committer: $committer $committerdt"
fi
echo "$m" > "$1"
确保脚本是可执行的:chmod +x svnmessage.sh
。并运行dcommit
,如:使用GIT_EDITOR
环境变量用于处理提交信息
GIT_EDITOR="/path/to/script/svnmessage.sh" git svn dcommit --edit
的--edit
选项将edit the commit message before committing to SVN
。有关更多信息,请参见git-svn
和git-var
。
您可以创建别名以使事情变得更简单:
git config --global alias.dcommit-edit '!GIT_EDITOR="$HOME/bin/svnmessage.sh" git svn dcommit --edit'
然后,只需使用git dcommit-edit
。
脚本依赖于如何git-svn.perl
虹吸管的git cat-file
输出创建SVN提交信息。使用相同的技术来提取作者和提交者信息。一个简单的承诺可能看起来像:
$ git cat-file commit 24aef4f
tree eba872d9caad7246406f310c926427cfc5e73c8d
parent 7dd9de9b5c68b9de1fc3b798edbab2e350ae6eac
author User <[email protected]>54806 -0500
committer User <[email protected]>54806 -0500
foo-27
脚本通常有.git/COMMIT_EDITMSG
传递给它的参数;其内容将包含将用于SVN提交消息的Git提交消息。
不完全。 这是关于重写日志,当你做“git svn dcommit”。 – 2010-06-11 11:37:36
我明白了。抱歉误会,我没有'git-svn'的经验。 – takeshin 2010-06-11 12:00:11