简体   繁体   English

我怎样才能从git status“在分支主服务器上\\ n什么都没提交..”到“在分支主服务器上\\ n您的分支是最新的\\ n什么都没有..”?

[英]How can i get from git status “On branch master \n Nothing to commit..” to “On branch master \n Your branch is up to date \n Nothing to ..” ?"

I am building a PHP application which controls a git repository. 我正在构建一个控制git存储库的PHP应用程序。 I have a sync function which executes the command git status and while "Your branch is up to date" is not returned, takes necessary actions like remote or local branch may be ahead. 我有一个执行命令git status的同步功能,虽然未返回“您的分支是最新的”,但需要采取必要的操作,例如远程或本地分支。

I also build the logic for if the local repo folder gets deleted then mkdir, chmod and git pull. 我还建立了逻辑,以便删除本地存储库文件夹,然后删除mkdir,chmod和git pull。 To test it, i deleted the local repo folder and the new local repo is created and git pull is successful. 为了测试它,我删除了本地存储库文件夹,并创建了新的本地存储库,并且git pull成功。

Now my logic is heavily dependent on the string "Your branch is up to date" but git status only returns "On branch master \\n Nothing .." where previously the your branch string used to be between the two statements returned now. 现在我的逻辑在很大程度上取决于字符串“您的分支是最新的”,但是git status仅返回“在分支主目录上\\ n Nothing ..”,以前,您的分支字符串曾经位于现在返回的两个语句之间。

I would like to ask how can i get from "On branch master \\n Nothing.." to "On branch master \\n your branch is up to date \\n Nothing.." ? 我想问一下如何从“在分支主服务器上\\ n什么都没有。”到“在分支主服务器上\\ n您的分支是最新的\\ n什么都没有。”?

I am using a PHP script to implement the above logic and use shell_exec() to execute git commands, collect output in a variable and use this->contains() to match status and act accordingly 我正在使用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
    }
}

I found the solution. 我找到了解决方案。 I used the below command to resolve my issue: 我使用以下命令解决了我的问题:

git branch --set-upstream-to=origin/master git branch --set-upstream-to =源/主

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

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