Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why post-merge git hook not running?

I just wanted to run a git hook(post-merge) to verify what are all the changes happened in the recent pull.

this is my post-merge script

#/usr/bin/env bash

echo "======> following are changes made to local repo <======"

git fetch && git log ..origin/master --pretty=format:"%s - %ar by %an (%h)"

echo "=======> ****************** <========"

I have given necessary file permission chmod +x post-merge

command git fetch && git log ..origin/master --pretty=format:"%s - %ar by %an (%h)" runs perfectly when i ran it manually.

But when i do a git pull origin master it is showing only

echo "======> following are changes made to local repo <======"
echo "=======> ****************** <========" 

Because git pull performs both git fetch and git merge i tried with

#/usr/bin/env bash

    echo "======> following are changes made to local repo <======"

    git log ..origin/master --pretty=format:"%s - %ar by %an (%h)"

    echo "=======> ****************** <========"

Where i am going wrong?

git version 1.9.1

Thanks

like image 644
Aparichith Avatar asked May 30 '26 20:05

Aparichith


1 Answers

that because post-merge is executed after git pull, that is when post-merge is executed, you HEAD is the same with origin/master, so you got empty output.

try this:

#/usr/bin/env bash

echo "======> following are changes made to local repo <======"

git fetch && git log ORIG_HEAD..origin/master --pretty=format:"%s - %ar by %an (%h)"

echo "=======> ****************** <========"

the key is ORIG_HEAD, which is the last value of HEAD before dangerous operation (includes merge)

for more infomation about ORIG_HEAD read HEAD and ORIG_HEAD in Git

like image 74
leo108 Avatar answered Jun 01 '26 21:06

leo108



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!