【问题标题】:Nothing happens on git pull hook (post-update)git pull hook 上没有任何反应(更新后)
【发布时间】:2018-12-14 10:05:37
【问题描述】:

当我在实时服务器上执行git pull 时,我以root 身份登录,因此所有修改或新文件的用户和组都设置为root:root

我已经在我的 post-update 挂钩文件中尝试过这个设置:

OWNER="example:example"
REPO_PATH="/home/example/public_html"

cd $REPO_PATH || exit
unset GIT_DIR
FILES="$(git diff-tree -r --name-only --no-commit-id)"
git merge FETCH_HEAD

for file in $FILES
    do 
    chown $OWNER $file
done

exec git update-server-info

当我运行 git pull 时,它什么也不做。

【问题讨论】:

  • 它绝对不应该做任何事情,因为git pull 不会调用更新后挂钩。
  • 哇!那么在 git pull 之后我应该使用什么钩子来修改新文件?
  • 同时考虑post-checkoutpost-merge;请参阅 contrib/hooks/setgitperms.perl 以获取工作示例。
  • @torek 如果您想将两个 cmets 添加为对此的正确答案,我很乐意将其标记为完成。

标签: git githooks post-update


【解决方案1】:

运行git pull 不会调用更新后挂钩:git pullgit fetch,后跟git rebasegit merge,或多或少,并且变基有效地以git checkout 结束,而合并是,好吧,合并。 (对于所谓的 fast-forward 合并,git merge 在内部执行类似于 git checkout 的操作,但也会更新当前分支名称。)因此,这两个钩子更适合用于这种工作。

Git 包含 a contrib/hooks/setgitperms.perl example script,它旨在用于 post-checkoutpost-merge 挂钩。

(还值得一提的是,在实时服务器上运行git pull 不一定是一个好的部署策略。Git 本身不是一个部署系统,无论是 push-to-deploy 还是 pull-to-deploy 本身都不够适用于许多现实世界的设置。它们可以用于有限的子集,但一般来说,请考虑构建或使用真实的部署系统。)

【讨论】:

    猜你喜欢
    • 2015-01-23
    • 2017-01-02
    • 2020-03-17
    • 2015-01-20
    • 2015-01-02
    • 2020-10-24
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    相关资源
    最近更新 更多