我有一个commit-msg钩子,用于我所有的本地提交。对于某个项目,我需要运行这个钩子。问题是,当我从其他分支合并时,我的一些同事没有运行这个commit-msg钩子。到目前为止,我一直在做
$ git rebase --interactive $commit_parent
如这里描述的那样。选择那些未正确完成的提交,重新编辑等。所有这些都是可行的,但手动进行非常繁琐。
我该如何自动化这个过程?挂钩不需要监督。
我有一个commit-msg钩子,用于我所有的本地提交。对于某个项目,我需要运行这个钩子。问题是,当我从其他分支合并时,我的一些同事没有运行这个commit-msg钩子。到目前为止,我一直在做
$ git rebase --interactive $commit_parent
如这里描述的那样。选择那些未正确完成的提交,重新编辑等。所有这些都是可行的,但手动进行非常繁琐。
我该如何自动化这个过程?挂钩不需要监督。
您可以使用自定义编辑器以自动方式实现这一目标:
#!/bin/bash
# Save to rebase_editor.sh, chmod +x it
file="$1"
if head -n1 "$file" | egrep -q '^pick' "$file" ; then
perl -pi -e 's/^pick/r/' "$file"
fi
然后运行:
GIT_EDITOR=./rebase_editor.sh git rebase -i <some-rev>
rebase -i
获取提交列表,并将每个pick
更改为r
(即reword
)。在这种模式下,git
会立即使用每个重定位提交的消息调用我们的“编辑器”(并且没有任何暂停,通常在pick
模式中可以更改提交本身)。根据“hooks”手册中对钩子的描述,我认为这很容易。
It takes a single parameter, the name of the file
that holds the proposed commit log message.
对于每个提交,只需运行钩子脚本:
git rev-list HEAD |while read h; do
git show --format='%B' $h > tmp && sh .git/hooks/commit-msg.sample tmp
done
rm tmp