Git, read latest commit message when committing Git, read latest commit message when committing git git

Git, read latest commit message when committing


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/shecho "# Previous commit:" >> $1git log -1 -p|sed 's/^\(.\)/# \1/g'  >> $1

should be enough.


You could write your own command? It might look something like this:

#!/bin/bashecho "Last commit message:"git log -1 --pretty=%B # only echo commit msg to consoleecho "Enter commit message:"read commitmsg # let user enter a commit messagegit commit -m "$commitmsg"

You would then add this file to your PATH.