Reputation: 2802
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?
Upvotes: 7
Views: 618
Reputation: 72755
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.
Upvotes: 5
Reputation: 27237
You could write your own command? It might look something like this:
#!/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"
You would then add this file to your PATH.
Upvotes: 1