简体   繁体   English

Git pre-receive hook newRev 问题

[英]Git pre-receive hook newRev issue

While executing pre-receive hook git show $newrev shows diff in $newRev but if while executing pre-receive hook I will go to repo and execute the same command git show $newrev it will return error fatal: bad object {newRev} .在执行前收到钩git show $newrev节目中DIFF $newRev但如果在执行pre-receive勾我会去回购和执行相同的命令git show $newrev它会返回错误fatal: bad object {newRev}

Git version: 2.22.0. Git 版本:2.22.0。 On Git 2.7.4 executing git show in repo doesn't return error.在 Git 2.7.4 git show在 repo 中执行git show不会返回错误。

pre-receive hook script when git show works correctlygit show正常工作时pre-receive hook script

#!/usr/bin/env bash
read oldrev newrev refname

git show $newrev

pre-receive hook script with sleep and manually run git show in repo pre-receive hook script带有睡眠的pre-receive hook script并在 repo 中手动运行git show

#!/usr/bin/env bash
read oldrev newrev refname

sleep 999
cd /repo
git show ae435ae1f9de55620d306cc82799ff20870f4238

fatal: bad object ae435ae1f9de55620d306cc82799ff20870f4238致命:坏对象ae435ae1f9de55620d306cc82799ff20870f4238

After investigating I understood that Git in pre-receive hook creates separate temp dir where it collects info about commit that came.经过调查,我了解到pre-receive钩子中的 Git 创建了单独的临时目录,它收集有关提交的信息。 For example temp dir name is objects/incoming-GsAsa .例如临时目录名称是objects/incoming-GsAsa

But Git knew about it only in pre-receive hook script because it set GIT_OBJECT_DIRECTORY and GIT_ALTERNATE_OBJECT_DIRECTORIES envs properly.但是 Git 只在pre-receive钩子脚本中知道它,因为它正确设置了GIT_OBJECT_DIRECTORYGIT_ALTERNATE_OBJECT_DIRECTORIES环境。

So, the answer for the question is to set properly GIT_OBJECT_DIRECTORY and GIT_ALTERNATE_OBJECT_DIRECTORIES vars.因此,问题的答案是正确设置GIT_OBJECT_DIRECTORYGIT_ALTERNATE_OBJECT_DIRECTORIES变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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