如何在git中比较本地和远程分支树?

artu-hnrq

此答案描述了如何获得两个分支之间的(文件)差异。

我很想知道如何知道远程分支提交了本地分支diff的数量

我的意思是,前面旁边后面的提交次数

埃尔皮·凯

比较两个随机分支AB,以查找有多少次A新提交B

git rev-list --count B..A

AB可能具有以下一种关系:

  1. A并且B是无关的分支;
  2. AB
  3. A领先B;
  4. A在后面B;
  5. A与分歧B

找出与的关系foo.sh

#!/bin/bash

A=$1
B=$2

merge_base=$(git merge-base $A $B)
if [[ "${merge_base}" = "" ]];then
    echo "$A and $B are unrelated"
else
    num_new_to_A=$(git rev-list --count $A..$B)
    num_new_to_B=$(git rev-list --count $B..$A)
    if [[ "${num_new_to_A}" -eq 0 ]] && [[ "${num_new_to_B}" -eq 0 ]];then
        echo "$A is up-to-date with $B"
    elif [[ "${num_new_to_A}" -eq 0 ]] && [[ "${num_new_to_B}" -gt 0 ]];then
        echo "$A is ${num_new_to_B} commits ahead of $B"
    elif [[ "${num_new_to_A}" -gt 0 ]] && [[ "${num_new_to_B}" -eq 0 ]];then
        echo "$A is ${num_new_to_A} commits behind $B"
    elif [[ "${num_new_to_A}" -gt 0 ]] && [[ "${num_new_to_B}" -gt 0 ]];then
        echo "$A is diverged with $B, ${num_new_to_B} commits ahead and ${num_new_to_A} commits behind"
    else
        :
    fi
fi

比较masterorigin/master

bash foo.sh master origin/master

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在Netbeans中比较GIT Remote Repo和本地

如何在本地和远程删除Git分支?

如何比较本地和远程git文件?

如何在 Git 中将本地分支转换为远程分支?

如何在Xcode中比较分支

如何在git中显示本地和远程分支之间的连接?

如何通过此设置将本地git分支与远程git分支进行比较?

如何重命名Git本地和远程分支名称?

如何合并远程和本地 Git 分支并检索丢失的文件

如何将本地git分支与其远程分支进行比较?

在本地和远程重命名Git分支?

如何在Git中完全用远程分支替换本地分支?

我如何在同一远程分支上有2个独立的本地Git分支

git rebase后,我的本地分支和远程分支分歧了

如何在Visual Studio Code中比较不同的分支

如何使用git用不同的本地分支覆盖远程分支

如何删除远程分支而不删除git上的本地分支?

使用Git时,如何在Visual Studio中刷新分支(本地/远程)?

如何在1步中将本地分支删除传播到远程-git,github

如何在我的本地存储库之前修复 Git 上的远程分支而不进行拉取

Git:如何交换两个本地和远程分支(Github)

重命名本地和远程Git存储库的master分支

Git Push给定本地和远程分支名称

查看(清单)在本地和远程分支之间更改的文件-git

是否可以从Git分支(本地和远程)删除特定的提交?

如何在源代码树中拉远程分支

git用远程分支替换本地分支

“git fetch”上的本地分支与远程分支

如何在本地删除 Git 分支?