首页 > 解决方案 > 我怎样才能从 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
    }
}

标签: phplinuxgit

解决方案


我找到了解决方案。我使用以下命令来解决我的问题:

git 分支 --set-upstream-to=origin/master


推荐阅读