git - 如何识别 Git 和 Mercurial 中的交叉 merge ?

标签 git mercurial merge git-merge

我想确定 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/

相关文章:

javascript - 如何使用相同的键合并数据

c# - 将 DLL 嵌入已编译的可执行文件中

git gui 可以很好地显示分支

version-control - 如何获取按最近使用顺序排列的 Mercurial (hg) 书签列表?

mercurial - 这个 Mercurial 工作流程 : named branch "dead" head? 有什么缺点吗

mercurial - Perforce 到 Mercurial 导入

sql-server - 将 SQL Server 数据库合并为 1

git - "fatal: You are on a branch yet to be born"在这种情况下意味着什么

windows - 如何为 Git-Bash 设置 16 种终端颜色?

git - git是否存储文件的读、写、执行权限?