Daniel Powell
Daniel Powell

Reputation: 8303

git show last checking when commiting

Is it possible to show the text of the last commit when I do a git commit.

I frequently need to check in and associate with a ticket number and I always tend to forget the number and have to go back and do a git log to find out the previous commit and get the ticket id, it would reduce a bit of friction of this was just included in the commit comments that are shown.

Upvotes: 0

Views: 171

Answers (3)

qqx
qqx

Reputation: 19495

You could use a prepare-commit-msg hook script to add comments about the most recent commit in the file used for editing the message for the next commit. A basic implementation would be:

#!/bin/sh
tmpf=`tempfile`
git show | sed 's/^/# /' > "$tmpf"
cat "$1" >> "$tmpf"
mv "$tmpf" "$1"

Upvotes: 1

You you are on Linux or Mac using git from the command line you could create a shell script called gitcommit:

git log -1
git commit $*

and then use gitcommit ... instead of git commit ...

Upvotes: 0

mgarciaisaia
mgarciaisaia

Reputation: 15650

Yes. You can create a post-commit-hook that shows the message log for the last commit (the one recently pushed).

I'd recommend you to read the Git Hooks section of the Pro Git. It even tells you how to get your last commit (git log -1 HEAD), but you probably simply want to git show HEAD or something like that.

Upvotes: 1

Related Questions