简体   繁体   English

php exec() - git push origin master无法正常工作,但其他git命令正在运行

[英]php exec() - git push origin master not working, but other git commands are working

I used below code : 我使用下面的代码:

    echo exec("git add . ");  //this is working  
echo exec("git commit -am 'first commit' "); //also working  
echo exec("git push origin master");  //NOT WORKING, also not showing any error . 

I chowned folder permissions from user to www-data . 我将用户的文件夹权限限制为www-data。 So, some git commands are working but 所以,一些git命令正在运行但是

GIT PUSH ORIGIN MASTER

is not working from php exec . 是不是从php exec工作。 What is the solution ? 解决办法是什么 ? Also, please tell me why PUSH in exec NOT showing any error or msg, how can i see those msgs . 另外,请告诉我为什么在exec中PUSH没有显示任何错误或消息,我怎么能看到这些消息。 Also,if possible, please provide me any good links for more advanced use of git commands from php exec . 另外,如果可能的话,请给我任何好的链接,以便更高级地使用php exec中的git命令。

Update : I also tried this : I added post-commit hook by creating file .git/hooks/post-commit 更新:我也试过这个:我通过创建文件.git / hooks / post-commit添加了post-commit钩子

I added this code to it : 我将此代码添加到其中:

git push origin master

But I didnt get any msg or error after commiting, it just commited but didnt do any push. 但我提交后没有得到任何消息或错误,它只是提交但没有做任何推动。

Thanks ! 谢谢 !

I assume the push command will try to push to a remote repository (ie not another folder on your system but a remote server behind SSH/HTTPS). 我假设push命令将尝试推送到远程存储库(即系统上的另一个文件夹,而不是SSH / HTTPS后面的远程服务器)。

In this case you are most likely missing a HTTPS client certificate HTTPS or an SSH key. 在这种情况下,您很可能缺少HTTPS客户端证书HTTPS或SSH密钥。 Your webserver (and therefore PHP) most likely runs as a different user and does not have access to the private key. 您的Web服务器(以及PHP)最有可能以不同的用户身份运行,并且无法访问私钥。 Next to that if the private key needs a password it will not work because the exec command is not an interactive session. 如果私钥需要密码,那么它将无法工作,因为exec命令不是交互式会话。

Anyway I heavily recommend you to use some sort of bindings and not calling the binaries. 无论如何,我强烈建议你使用某种绑定而不是调用二进制文件。 Any direct call will start a new process and this is way more inefficient that calls into a library. 任何直接调用都将启动一个新进程,这对于调用库来说效率更低。

Have you checked which branch your are on? 你检查过你所在的分店吗? 'git status' will tell you. 'git status'会告诉你。

I'd also recommend working on a branch and not directly on master. 我还建议在分支机构工作,而不是直接在主机上工作。

git branch dev_test git branch dev_test

git checkout dev_test git checkout dev_test

git add . git add。

git commit -a -m "first comment" git commit -a -m“第一条评论”

git push origin dev_test git push origin dev_test

git checkout master git checkout master

git merge dev_test git merge dev_test

git push origin master git push origin master

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM