Git,在提交时读取最新的提交消息 [英] Git, read latest commit message when committing
问题描述
当我提交时,此文本跳转:
请输入提交信息以进行更改。用'#'开始
的行将被忽略,并且一条空的消息将中止提交。
在分支大师
上您的分支在2次提交之前领先于origin / master。
要提交的更改:
新文件:modules / new_file.txt
我想要的是让这个内容丰富的文本向我显示上次提交的消息,而不需要通过 git log
, git show
或类似的东西。
例如
(...)
要提交的更改:
新文件:modules / new_file.txt
上一个提交消息:
[FIX]修复了foo.bar模块
这与这个问题,但没有一个答案实际上是回答这个问题,所以我猜OP只是问了一下有点错误? git hook ,它叫做 prepare-commit-msg
,它是生成这个提交消息模板的东西。您的 .git
目录中应该有一个 prepare-commit-msg.sample
文件。重命名它以移除 .sample
,然后编辑它以包含 git log -1
或其他任何你可能想要的当你提交时你会得到它。
类似于这样的
#!/ bin / sh
echo#previous commit:>> $ 1
git log -1 -p | sed's / ^ \(。\)/#\ 1 / g'>> $ 1
应该足够了。
When I am committing, this text jumps up:
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
What I want is to let this informative text also show me the message of my last commit, without me needing to go through git log
, git show
or anything similar.
E.g.
(...)
Changes to be committed:
new file: modules/new_file.txt
Previous commit message:
[FIX] Fixed the foo.bar module
This is exactly the same as this question, but none of the answers was actually answering the question, so I guess OP just asked it a bit wrong?
There is a git hook called prepare-commit-msg
which is what generates this commit message template. There should be a prepare-commit-msg.sample
file in your .git
directory by default. Rename it to remove the .sample
and then edit it to include a git log -1
or anything else you might want and you'll get it when you commit.
Something like this
#!/bin/sh
echo "# Previous commit:" >> $1
git log -1 -p|sed 's/^\(.\)/# \1/g' >> $1
should be enough.
这篇关于Git,在提交时读取最新的提交消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!