开发者

Git to svn: Adding commit date to log messages

How should I do to have the author (or committer) name/date added to the log message when "dcommitting" to svn?

For example, if the log message in Git is:

This is a nice modif

I'd like to have the message in svn be something like:

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

(Note that 开发者_StackOverflow社区I'm mainly interested in the date, since I already mapped svn users in .svn-authors)

Any simple way? Hook needed? Other suggestion?

(See also: http://article.gmane.org/gmane.comp.version-control.git/148861)


One way to accomplish this is by using a script, the GIT_EDITOR environment variable and the dcommit --edit option.

Save the following to a file, let's call it 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"

Make sure the script is executable: chmod +x svnmessage.sh. And run your dcommit like:

GIT_EDITOR="/path/to/script/svnmessage.sh" git svn dcommit --edit

The --edit option will edit the commit message before committing to SVN using the GIT_EDITOR environment variable for processing the commit message. See git-svn and git-var for further information.

You could create an alias to make things a bit easier:

git config --global alias.dcommit-edit '!GIT_EDITOR="$HOME/bin/svnmessage.sh" git svn dcommit --edit'

Then just use git dcommit-edit.


The script relies on how git-svn.perl siphons the git cat-file output to create the SVN commit message. The same technique is used to extract the author and committer information. A simple commit might look like:

$ 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

The script will typically have .git/COMMIT_EDITMSG passed to it as a parameter; the contents of which will contain the Git commit message that will be used for the SVN commit message.


Is it just about changing log output format?

git log --pretty="format:%s %an %ae %cn %d"
git help log
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜