【问题标题】:git post-receive hook and multiple commits in one pushgit post-receive 钩子和一次推送中的多个提交
【发布时间】:2015-08-10 17:02:03
【问题描述】:

我试图了解当多个提交被推送到一起时,git post-receive 钩子会发生什么。从我看到的文档和示例中,我希望它接受来自 STDIN 的引用列表,允许我对每个单独的提交采取行动,但它似乎不是这样工作的?这是我所拥有的:

我的 post-receive 钩子,显然这只是为了测试:

#!/usr/bin/perl

use Data::Dumper;
my @input = <STDIN>;    
print STDERR Dumper(\@input);

我编辑了两个文件,分别提交:

nelson% git log origin/master..HEAD
commit 93f96201f2cfd3e83a9a609ec644dc873aefeb17
Author: cecukemon <cecukemon@...>
Date:   Thu May 28 11:09:19 2015 +0200

    commit 2

commit 8bbcc8370101d44c8a7302fb365f257e62a61e9d
Author: cecukemon <cecukemon@...>
Date:   Thu May 28 11:09:09 2015 +0200

    commit 1

将它们合二为一:

nelson% git push
Counting objects: 6, done.
Delta compression using up to 12 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (6/6), 542 bytes | 0 bytes/s, done.
Total 6 (delta 0), reused 0 (delta 0)
remote: $VAR1 = [
remote:           'fa45b972bb59fbe92d7331cfad5d2933a53414ce 93f96201f2cfd3e83a9a609ec644dc873aefeb17 refs/heads/master
remote: '
remote:         ];
To /home/cecukemon/hooktest
   fa45b97..93f9620  master -> master

两次提交均已成功推送:

nelson% git log origin/master..HEAD
nelson%

并且 post-receive 挂钩已成功执行,但我只在参考列表中看到其中一个提交(推送输出中的 $VAR1)。

我是否从根本上误解了接收后挂钩的工作原理?

【问题讨论】:

    标签: git githooks git-post-receive


    【解决方案1】:

    您会获得旧的和新的 ref 值,因此如果添加了多个提交,您通常可以使用 $old..$new 获得它们(例如传递给 git rev-list)。

    while read old new ref; do
            while read commit; do
                    # check the commit here
            done <<EOD
    $(git rev-list $old..$new)
    EOD
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-15
      • 2013-02-02
      • 1970-01-01
      • 2013-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-17
      相关资源
      最近更新 更多