Git to svn:为日志消息添加提交日期

时间:2010-06-11 07:06:23

标签: svn git date git-svn message

如何将作者(或提交者)的姓名/日期添加到日志中 “dcommitting”到svn时的消息?

例如,如果Git中的日志消息是:

This is a nice modif

我希望svn中的消息类似于:

This is a nice modif
-----
Author: John Doo <John.Doo@company.com>  2010-06-10 12:38:22
Committer: Nice Guy <nguy@acme.org>  2010-06-10 14:05:42

(请注意,我主要对日期感兴趣,因为我已经在.svn-authors中映射了svn用户)

有什么简单的方法吗?胡克需要吗?其他建议?
(另见:http://article.gmane.org/gmane.comp.version-control.git/148861

2 个答案:

答案 0 :(得分:3)

实现此目的的一种方法是使用脚本,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="/path/to/script/svnmessage.sh" git svn dcommit --edit

--edit选项将edit the commit message before committing to SVN使用GIT_EDITOR环境变量来处理提交消息。有关详细信息,请参阅git-svngit-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 <user@acme.com> 1321054806 -0500
committer User <user@acme.com> 1321054806 -0500

foo-27

脚本通常会将.git/COMMIT_EDITMSG作为参数传递给它;其内容将包含将用于SVN提交消息的Git提交消息。

答案 1 :(得分:-1)

它只是改变日志输出格式吗?

git log --pretty="format:%s %an %ae %cn %d"
git help log
相关问题