一種方式是通過使用腳本,該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