Git,提交时读取最新提交消息
当我提交时,此文本会跳起来:Git,提交时读取最新提交消息,git,git-commit,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:
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
或任何类似的内容
例如
这与完全相同,但没有一个答案真正回答了这个问题,所以我猜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"
然后将此文件添加到路径中。有一个名为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
应该足够了。不,我使用的是带有Atom、Sublime或Notepad++的Windows。我还没有决定,但目前我正在测试Atom。好吧,我对bash脚本不太熟悉,试图添加
echo something
,dir
,ls
,在这上面什么也做不了。你能提供一个简单的工作示例吗?编辑:我看到它在打开提交编辑器之前在GitBash中吐出了一些东西。所以我的问题是进入commit消息中的comment部分
#!/bin/sh
echo "# Previous commit:" >> $1
git log -1 -p|sed 's/^\(.\)/# \1/g' >> $1