php - 我怎样才能从 git status "On branch master \n Nothing to commit.." 到 "On branch master \n Your branch is up to date \n Nothing to .." ?
问题描述
我正在构建一个控制 git 存储库的 PHP 应用程序。我有一个执行命令 git status 的同步功能,虽然没有返回“您的分支是最新的”,但可能会采取必要的操作,例如远程或本地分支。
我还构建了如果本地 repo 文件夹被删除然后 mkdir、chmod 和 git pull 的逻辑。为了测试它,我删除了本地 repo 文件夹并创建了新的本地 repo,并且 git pull 成功。
现在我的逻辑在很大程度上依赖于字符串“你的分支是最新的”,但 git status 只返回“在分支 master \n Nothing ..”之前你的分支字符串曾经位于现在返回的两个语句之间。
我想问我如何从“在分支主机上\n 什么都没有..”到“在分支主机上\n 你的分支是最新的\n 什么都没有..”?
我正在使用 PHP 脚本来实现上述逻辑并使用 shell_exec() 来执行 git 命令,在变量中收集输出并使用 this->contains() 来匹配状态并采取相应措施
Sync()
{
//If folder was deleted
if(!is_dir($repo))
{
if(mkdir($repo))
{
shell_exec(chmod)
shell_exec(git pull)
}
}
//For rest of the cases
$output = shell_exec("git status")
while(!this->contains("Your branch is up to date", $output))
{
//Take necessary actions
}
}
解决方案
我找到了解决方案。我使用以下命令来解决我的问题:
git 分支 --set-upstream-to=origin/master
推荐阅读
- c# - 不支持 MongoDB Drive linq
- javascript - 在 ie11 上刷新后 React App 无法加载
- javascript - 如何为 Web 开发安装 NumJs?
- java - 使用 JAMOD 读取正确的 Schneider Momentum PLC 寄存器或线圈地址
- python - 将输出标签值保存到 csv
- python - 在两个 RaspberryPi 之间使用 Python xmlrpc 会导致连接被拒绝错误
- javascript - HTML & CSS: 带有基于 Scroll 的覆盖导航栏的嵌入式视频
- angular - 从 Angular 到 Spring 的多部分发布请求
- python - Python Twisted/Reactor 无法将消息发送到服务器/客户端
- python - 如何计算熊猫系列中列表的元素