Git,提交时读取最新的提交消息

chw*_*hwi 6 git 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
 Your branch is ahead of 'origin/master' by 2 commits.

 Changes to be committed:

    new file:   modules/new_file.txt
Run Code Online (Sandbox Code Playgroud)

我想要的是让这个信息文本也显示了我最后的消息提交,没有我需要去通过git log,git show或任何类似.

例如

(...)

 Changes to be committed:

    new file:   modules/new_file.txt

 Previous commit message:
    [FIX] Fixed the foo.bar module
Run Code Online (Sandbox Code Playgroud)

这与这个问题完全相同,但没有一个答案实际上回答了这个问题,所以我想OP只是问它有点不对劲?

Nou*_*him 5

有一个git hook被调用prepare-commit-msg,它生成这个提交消息模板.默认情况下prepare-commit-msg.sample,您的.git目录中应该有一个文件.重命名它以删除它.sample,然后编辑它以包含git log -1您可能想要的任何其他内容,并在提交时获得它.

像这样的东西

#!/bin/sh

echo "# Previous commit:" >> $1
git log -1 -p|sed 's/^\(.\)/# \1/g'  >> $1
Run Code Online (Sandbox Code Playgroud)

应该够了.