繁体   English   中英

为什么合并后的git hook没有运行?

[英]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 fetchgit 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM