首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用PHP exec在bat文件中执行git命令

使用PHP exec在bat文件中执行git命令
EN

Stack Overflow用户
提问于 2014-12-01 18:55:37
回答 1查看 739关注 0票数 2

我正在尝试用PHP、exec和一个批处理文件执行多个git命令。当我从cmd窗口执行bat文件时,它运行得很好。但由于某些原因,当我使用exec调用bat文件时(在PHP中),它只执行until call git add -A。Commit命令不会执行。当我手动执行它( commit命令),然后再次运行脚本时,文件将被推送到存储库...问题似乎是,如果脚本是通过PHP中的exec执行的,那么它不想提交文件。

这是我的php:

exec('C:\wamp\www\git.bat "C:/wamp/www/project" "project"');

这是我的bat文件:

@echo off
set drupal_root=%1
set repo_name=%~2

pushd %drupal_root%
call git init
call git remote add origin https://repo-url/%repo_name%.git
call git add -A
call git commit -m "Initial commit"
call git push origin master

有谁知道原因是什么吗?

EN

回答 1

Stack Overflow用户

发布于 2018-06-24 04:06:12

在"Windows shortcut to run git bash script“之后,尝试执行bash脚本(使用Git for Windows bash shell),而不是bat脚本:

exec('C:\Git\bin\sh.exe" --login -i C:\wamp\www\myscript.sh "C:/wamp/www/project" "project"');

(将C:\Git\bin\sh.exe替换为安装Git for Windows的路径。)

使用myscript.sh

#!/bin/bash

drupal_root=$1
repo_name=$2

cd $drupal_root
git init
git remote add origin https://repo-url/${repo_name}.git
git add -A
git commit -m "Initial commit"
git push -u origin master
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27226824

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档