【问题标题】:Git global config issue when run through script通过脚本运行时的 Git 全局配置问题
【发布时间】:2016-06-25 21:36:18
【问题描述】:

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

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

[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

我该如何解决这个问题?

【问题讨论】:

    标签: linux git terminal automation


    【解决方案1】:

    您需要检查 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

    【讨论】:

    • 谢谢。我将采用这种方法。我还发现以下工作: HOME= git commit -m "My Message"
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-03
    • 2016-09-13
    • 2012-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多