我有一个commit-msg钩子,我为所有本地提交运行,对于某个项目,我需要运行.问题是,当我从其他叉子拉进来时,我的一些同胞没有运行这个commit-msg钩子.到目前为止,我一直在做
$ git rebase --interactive $commit_parent
Run Code Online (Sandbox Code Playgroud)
作为概括非常相似这里.选择未正确完成的提交,重新编辑等.一切都非常可行,但我手工做的也很乏味.
我该如何自动化?钩子不需要疏忽.
这可以使用自定义编辑器以自动方式实现:
#!/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
Run Code Online (Sandbox Code Playgroud)
然后运行:
GIT_EDITOR=./rebase_editor.sh git rebase -i <some-rev>
Run Code Online (Sandbox Code Playgroud)
在第一次调用时,我们的“编辑器”将从 获取提交列表rebase -i,其中每个提交都会更改pick为r(即reword)。在这种模式下,git将立即开始调用我们的“编辑器”,并提供每个重新基址提交的消息(并且不会像在pick您可以更改提交本身的模式下通常造成的任何暂停)。