我假設你想獲得倉庫中任何分支之間的縱橫交錯合併數量,而不是兩個分支機構交叉合併的次數。在這種情況下,下面的shell腳本應該做的Git:
#!/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"
對於水銀,其ancestor()
revset和debugancestor
命令既可惜只列出最大的共同祖先,並不是所有祖先的名單,所以我無法在此提出解決方案。
這是一個有趣的鏈接,但超過6歲...我不知道什麼新的/修訂版(與更多汞/ Git/Bzr輸入)看起來像... – 2012-06-14 21:27:09
你可能想重新命名標題說「三路合併」取而代之,因爲我從未聽說過任何地方的「交叉融合」...... – poke
@poke,閱讀鏈接。三向合併!=十字交叉合併。 Criss交叉合併是當分支A合併分支B更改時,分支B合併分支A更改時。在A→B或B→A的稍後時間點使用3向合併可能會導致合併過程中的錯誤。 –