Sarseth Sarseth - 1 year ago 166
Git Question

pre-receive hook - how to get messages of commits

How to get messages of commits that are received by server in pre-receive hook using bash?

I've tried to print:

echo >&2 $1 $2 $3

but only I get:

remote: 62e1ce5353f74f21eafac129dcff0074b2cc7a19 f58a366385ba105ecv1e2f3fbfe99ca60be737c72 refs/heads/master

Answer Source

As far as I remember you get the old hash, the new hash and the ref that is pushed. So just use git-log to get what you want.

Just the subject lines: git log --format="%s" $1..$2
Just the body lines: git log --format="%b" $1..$2
Subject and body lines: git log --format="%B" $1..$2

For more format options, read the man page of git log

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download