gpt4 book ai didi

linux - 通过脚本运行时的 Git 全局配置问题

转载 作者:太空狗 更新时间:2023-10-29 12:01:10 25 4
gpt4 key购买 nike

我有一个带有 Web 界面的 PHP 脚本,用于向现在自动化的流程提供输入。我试图通过 PHP 的 exec 执行 git 命令来在此过程中包括提交和推送到 Git。我能够 pull 入远程存储库,添加文件并获取它的状态。但是,我在尝试提交更改时遇到了问题。

当我尝试提交时,我得到:

[0] => 
[1] => *** Please tell me who you are.
[2] =>
[3] => Run
[4] =>
[5] => git config --global user.email "you@example.com"
[6] => git config --global user.name "Your Name"
[7] =>
[8] => to set your account's default identity.
[9] => Omit --global to set the identity only in this repository.
[10] =>
[11] => fatal: unable to auto-detect email address (got 'tim@tim.(none)')

我的理解是 Git 没有解析我在 ~/.gitconfig 的全局配置,它可以在通过终端正常执行时解析。我在我的用户和组下运行 Apache。当我尝试运行上面建议的命令时,我得到:

[0] => fatal: $HOME not set

我该如何解决?

最佳答案

您需要检查 Apache 中可用的环境变量。你可以使用

http://php.net/manual/en/function.get-defined-vars.php

Apache 以 root 身份启动并切换到非特权用户,但未为该用户设置 env 变量参见此处..

https://serverfault.com/questions/179833/apache2-user-home-directory-lock-to-root

请注意,Linux 系统上的主目录设置在/etc/passwd 中。这是一个例子

www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin

但在 Apache 中,这只是设置文档根目录,因为它没有像普通登录那样设置环境变量,即读取配置文件等。您可以在 Apache 中设置环境变量,使用

SetEnv HOME/home/foo

关于linux - 通过脚本运行时的 Git 全局配置问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35926700/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com