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


Executing git commands in bat file with PHP exec

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

这是我的 php:

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

这是我的蝙蝠文件:

@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

有人知道原因可能是什么吗?

在"运行 git bash 脚本的 Windows 快捷方式"之后,尝试执行 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