通过PHP执行git命令 [英] Executing git commands via PHP
问题描述
如何使用php执行git命令(如 git add。
和 git commit -m
)?
对于一个项目来说,它创建了一个用于维护学术项目的中央存储库工具。
$ b
exec()似乎没有
<?php
$ path =/ var / www / repos / $ _ POST [project ];
$ a ='';
chdir($ path);
exec(git add。);
exec(git commit -m'message');
echo< h3 align = center>成功提交所有文件。< / h3>;
?>
它是可能的。我在我的一个项目中实现了它。
但是你应该小心权限。
在linux上,通常执行 exec
命令使用 www-data
用户。
因此您应该允许 www-data
在您的工作目录中写入和读取。
肮脏的方式是: chmod o + rw -R git_directory
How can git commands like git add .
and git commit -m
be executed using php?
It is for a project that creates a centralized repository facility for maintaining academic projects.
exec() didn't seem to work.
<?php
$path = "/var/www/repos/$_POST[project]";
$a='';
chdir($path);
exec("git add .");
exec("git commit -m'message'");
echo "<h3 align = center> Succesfully commited all the files.</h3>";
?>
It is definetly possible. I implemented it in one of my projects. However you should be careful about permissions.
On linux, usually, the exec
command will execute using the www-data
user.
So you should allow www-data
to write and read on your work directory.
One quick and dirty way to do it is : chmod o+rw -R git_directory
这篇关于通过PHP执行git命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!