比较两个随机分支A
和B
,以查找有多少次A
新提交B
:
git rev-list --count B..A
A
并B
可能具有以下一种关系:
A
并且B
是无关的分支;A
与B
;A
领先B
;A
在后面B
;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
比较master
和origin/master
:
bash foo.sh master origin/master
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句