[英]why post-merge git hook not running?
我只是想运行一个git hook(合并后)来验证最近的pull中发生了什么变化。
这是我的合并后脚本
#/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 "=======> ****************** <========"
我在chmod +x post-merge
给了chmod +x post-merge
必要的文件权限
命令git fetch && git log ..origin/master --pretty=format:"%s - %ar by %an (%h)"
在我手动运行时运行完美。
但是当我做一个git pull origin master
它只显示
echo "======> following are changes made to local repo <======"
echo "=======> ****************** <========"
因为git pull
执行git fetch
和git merge
我尝试过
#/usr/bin/env bash
echo "======> following are changes made to local repo <======"
git log ..origin/master --pretty=format:"%s - %ar by %an (%h)"
echo "=======> ****************** <========"
我哪里错了?
git版本1.9.1
谢谢
因为post-merge
是在 git pull
之后执行的,也就是在执行post-merge
,你的HEAD与origin/master
相同,所以你得到了空输出。
试试这个:
#/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 "=======> ****************** <========"
关键是ORIG_HEAD
,它是危险操作之前HEAD的最后一个值(包括合并)
有关ORIG_HEAD
更多信息,请阅读Git中的HEAD和ORIG_HEAD
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.