Git,提交时阅读最新的提交信息
Git, read latest commit message when committing
当我提交时,这段文字跳了起来:
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
我想要的是让这个信息文本也向我显示我上次提交的消息,而不需要我通过 git log
、git show
或任何类似的东西。
例如
(...)
Changes to be committed:
new file: modules/new_file.txt
Previous commit message:
[FIX] Fixed the foo.bar module
这和this question完全一样,但是none的答案其实是在回答问题,所以我猜OP只是问的有点不对?
你可以自己写命令吗?它可能看起来像这样:
#!/bin/bash
echo "Last commit message:"
git log -1 --pretty=%B # only echo commit msg to console
echo "Enter commit message:"
read commitmsg # let user enter a commit message
git commit -m "$commitmsg"
然后您可以将此文件添加到您的 PATH。
有一个名为 prepare-commit-msg
的 git hook 生成此提交消息模板。默认情况下,.git
目录中应该有一个 prepare-commit-msg.sample
文件。重命名它以删除 .sample
,然后编辑它以包含 git log -1
或您可能想要的任何其他内容,您将在提交时获得它。
像这样
#!/bin/sh
echo "# Previous commit:" >>
git log -1 -p|sed 's/^\(.\)/# /g' >>
应该够了。
当我提交时,这段文字跳了起来:
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
我想要的是让这个信息文本也向我显示我上次提交的消息,而不需要我通过 git log
、git show
或任何类似的东西。
例如
(...)
Changes to be committed:
new file: modules/new_file.txt
Previous commit message:
[FIX] Fixed the foo.bar module
这和this question完全一样,但是none的答案其实是在回答问题,所以我猜OP只是问的有点不对?
你可以自己写命令吗?它可能看起来像这样:
#!/bin/bash
echo "Last commit message:"
git log -1 --pretty=%B # only echo commit msg to console
echo "Enter commit message:"
read commitmsg # let user enter a commit message
git commit -m "$commitmsg"
然后您可以将此文件添加到您的 PATH。
有一个名为 prepare-commit-msg
的 git hook 生成此提交消息模板。默认情况下,.git
目录中应该有一个 prepare-commit-msg.sample
文件。重命名它以删除 .sample
,然后编辑它以包含 git log -1
或您可能想要的任何其他内容,您将在提交时获得它。
像这样
#!/bin/sh
echo "# Previous commit:" >>
git log -1 -p|sed 's/^\(.\)/# /g' >>
应该够了。