git commit
打开文本编辑器并显示有关要提交的更改的一些信息:
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
我想扩展此模板以显示
N
最后提交消息的第一行和/或。我怎么能这样做?
答案 0 :(得分:10)
这将使用git hooks
。
.git/hooks/
prepare-commit-msg
#!/bin/sh
ORIG_MSG_FILE="$1" # Grab the current template
TEMP=`mktemp /tmp/git-msg-XXXXX` # Create a temp file
trap "rm -f $TEMP" exit # Remove temp file on exit
MSG=`git log -1 --pretty=%s` # Grab the first line of the last commit message
(printf "\n\n# Last Commit: %s \n\n" "$MSG"; cat "$ORIG_MSG_FILE") > "$TEMP" # print all to temp file
cat "$TEMP" > "$ORIG_MSG_FILE" # Move temp file to commit message
chmod +x prepare-commit_message
从Enhancing git commit messages
借来的想法您可以使用%b
和%B
获取整个提交消息,但可能会遇到多行提交问题。可能会对%-b
和%-B
感兴趣,或只是在Documentation中阅读更多内容(滚动到格式)