【问题标题】:Git: How to find whether origin/master is equivalent of (local) master?Git:如何查找 origin/master 是否等同于(本地)master?
【发布时间】:2012-09-27 16:37:07
【问题描述】:

git fetch 通过网络从origin/master 获取最新的快照到本地主机。它不会合并,只是获取快照。在git fetch 之后,如果我们执行git status,它将告诉我们(本地)master 是领先还是落后于origin/master

我想要的只是一个 git 命令,它会告诉我们(本地)master 的内容是否等同于origin/master 的内容。显然,它必须通过网络来确定这一点,但它不应该打印任何关于其发现的消息(如git fetch 或任何其他 git 命令的输出),最后,只输出yes/true(如果等效)或no/false(如果不同)或类似的东西。

是否有任何 git 内部命令或 api 可以做到这一点?!

【问题讨论】:

    标签: git git-diff git-fetch git-status


    【解决方案1】:

    您可以使用-q 标志使git fetch 静音:

    git fetch -q
    if [ "$(git rev-parse origin/master)" == "$(git rev-parse master)" ]; then
        echo yes
    else
        echo no
    fi
    

    【讨论】:

      【解决方案2】:

      我终于用了下面sn-p的代码。

      output=`git fetch --dry-run 2>&1`
      
      if [ "$output" != "" ]; then
          echo "***********************************************"
          echo "*                    ERROR                    *"
          echo "* Your git source directory is not up to date *"
          echo "***********************************************"
      fi
      

      解析git fetch --dry-run的输出时出现问题但发现控制台消息属于stderrGit: unable to redirect/parse the output of 'git fetch --dry-run' command

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-07-27
        • 2012-05-22
        • 2012-01-31
        • 2011-02-22
        • 2013-05-09
        • 1970-01-01
        相关资源
        最近更新 更多