我想确定 criss cross merges 的数量它存在于某些 Git 和 Mercurial 开源项目中,仅供研究之用。关于如何实现这一点有什么建议吗?
如果 merge 有两个不同的共同祖先,则可以确定交叉 merge 。它正在为 Mercurial 开发一个新的 merge 策略,称为 consensus merge这将扩展 ancestor.ancestor() 代码以返回所有最伟大的共同祖先。我还找不到这段新代码,但它会有很大帮助。
我不太了解 Git,但它肯定有类似的东西。
最佳答案
我假设您想要获取存储库中任何分支之间的交叉 merge 数,而不是两个分支被交叉 merge 的次数。在这种情况下,Git 应该执行以下 shell 脚本:
#!/bin/sh
# Get the list of branches and convert it to an array.
branches=$(git for-each-ref --format='%(refname:short)' refs/heads/)
branches=( $branches )
N=${#branches[*]}
cc_merges=0
# Loop over all combinations of two branches.
for ((i=0; i<N-1; ++i)); do
for ((k=i+1; k<N; ++k)); do
a=${branches[$i]}
b=${branches[$k]}
bases=$(git merge-base --all $a $b | wc -l)
if [ $bases -gt 1 ]; then
let "cc_merges += 1"
fi
done
done
echo "Number of criss-cross merges in repository: $cc_merges"
不幸的是,对于 Mercurial,它的 ancestor()
revset 和 debugancestor
命令只列出了最大的共同祖先,而不是所有祖先的列表,所以我无法在这里提出解决方案。
关于git - 如何识别 Git 和 Mercurial 中的交叉 merge ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11041499/