[英]Using a PHP script as a post-commit hook, to trigger a bash script, to do a git-pull?
[英]Cannot do Git Commit on Windows / PHP
我正在使用Windows
/ PHP
。
通过使用PHP
脚本,我想进行commit
但是此操作失败。
为此,我使用以下代码:
<?
$command = "git commit -am .";
shell_exec($command);
?>
我还尝试使用chdir
来确保我位于Git存储库目录中,但是它不起作用(无论如何,我认为我不需要chdir
。问题是另一回事)。
通常从Windows console
我使用上面的相同命令(效果很好):
> git commit -am .
另外,如果从Windows控制台执行:
> php myscript.php
它工作正常。 但是,如果通过浏览器访问URL:
http://localhost/mysite/myscript.php
然后,提交不会通过。 但是正如我之前说过的那样,可以从浏览器中正确读取状态。
另一方面,如果我只是通过以下方式检查status
:
<?
$command = "git status";
$output = shell_exec($command);
echo $output
?>
然后正确返回Git status
。
关于如何通过Windows
PHP
进行commit
任何想法?
[编辑1]
我检查了Apache错误日志,发现每次尝试进行提交时,都会出现一个错误,提示我需要指定电子邮件和名称。 然后,我做到了(也通过PHP)。 但是现在我又遇到了另一个错误,它说:致命的:-a路径没有意义。 (在Apache错误日志上),当我尝试通过PHP进行以下提交时:shell_exec(“ git commit -am'my commit message here'”);。 你知道现在该怎么办吗?
使用git add .
添加文件git add .
并提供消息作为-m
的字符串参数:
提交: -am
$command = 'git commit -am "php wuz here"';
$escaped_command = escapeshellcmd($command);
shell_exec($escaped_command);
编辑1
git commit -am .
也为我工作,也许您只需要使用escapeshellcmd
和单引号即可。 测试时,我在使用外部双引号时遇到了麻烦。
编辑2
Windows 7的
编辑3
解决方案(由线程作者验证。有效!):
$command = 'git config user.name "Will Smith"';
$escaped_command = escapeshellcmd($command);
$result = shell_exec($escaped_command);
$command = 'git config user.email "myemail@gmail.com"';
$escaped_command = escapeshellcmd($command);
$result = shell_exec($escaped_command);
$command = 'git commit -am "my commit message here"';
$escaped_command = escapeshellcmd($command);
$result = shell_exec($escaped_command);
重要事项:请注意:
escapeshellcmd
Apache log
对于了解幕后发生的事情(并进行调试)非常重要
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.