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?
Viewing a list of the latest commits. If you want to see what's happened recently in your project, you can use git log . This command will output a list of the latest commits in chronological order, with the latest commit first.
# open the git config editor $ git config --global --edit # in the alias section, add ... [alias] lastcommit = rev-parse HEAD ... From here on, use git lastcommit to show the last commit's hash. Save this answer.
`git log` command is used to view the commit history and display the necessary information of the git repository. This command displays the latest git commits information in chronological order, and the last commit will be displayed first.
By default git diff will show you any uncommitted changes since the last commit.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With