在git post-checkout钩子中,如何确定用户是否从HEAD分支?

时间:2013-11-27 23:17:32

标签: git

我有一个post-checkout挂钩,如果用户刚刚执行了操作,则无法运行:

git checkout -b somebranch

如果前一个分支指向与新分支相同的提交,您如何计算?

1 个答案:

答案 0 :(得分:1)

git help hooks报告:

   post-checkout
       This hook is invoked when a git checkout is run after having updated the worktree. The hook is given three parameters:
       the ref of the previous HEAD, the ref of the new HEAD (which may or may not have changed), and a flag indicating whether
       the checkout was a branch checkout (changing branches, flag=1) or a file checkout (retrieving a file from the index,
       flag=0). This hook cannot affect the outcome of git checkout.

请注意结帐时已经完成调用的部分,以及“不能影响git checkout结果”的部分。

然而,它传递了前一个和新HEAD的参考,所以你可以比较那些以确定你是否真的移动了,并根据那个比较来做(或不做)...