【问题标题】:Finding an approximate Git fork-point寻找一个近似的 Git 分支点
【发布时间】:2016-01-14 15:01:58
【问题描述】:

通常当供应商发布他们的内核时,他们要么发布一个 tarball,要么将所有提交压缩为一个(本文中的分支 public);我无权访问internal。我正在尝试创建一个分支 (recovery) 以清楚地识别主线内核 (original) 所做的更改。

original: A--B--C--D--E--F
internal: A--B--C--D
                    \
                     G--I--J
public:   J

因为public 不包含ABCD,所以使用git merge-base --fork-point 将无法识别与original 的任何精确匹配。理想情况下,我希望使用public(可能是D)来识别original 中具有最少不同行(或文件)的提交。一旦我确定DJ 最相似,我就可以创建recovery

recovery: A--B--C--D--J

我可以将public 重新定位到originalHEAD,但在我的历史中我最终会得到EF。这会给大型存储库增加大量噪音,并且看起来好像这些更改已在 J 中恢复(实际上它们从未存在于 internal 中)。

attempt:  A--B--C--D--E--F--J 

【问题讨论】:

  • 换句话说,您在提交 (A,B,C,D,E,F) 中寻找与 J 相比差异最少的提交?
  • 没错,这就是目标。

标签: git merge git-merge fuzzy-comparison


【解决方案1】:

以下脚本应该可以解决问题。它找到给定范围内的所有提交,然后估计每个提交与参考提交之间的不同行数,并找到最小差异。

#!/bin/bash

commit_to_compare_with=d67e
commit_range=1cb1d..e172

list_of_commits=($(git rev-list $commit_range))
num_of_commits=${#list_of_commits[@]}
minimal_diff_count=100000000

echo
echo Found $num_of_commits commits in the range $commit_range
echo

count_lines_of_diff() { git diff $1 $2 | wc -l; }

for c in "${list_of_commits[@]}"
do
  diff_count=$(count_lines_of_diff $commit_to_compare_with $c)
  echo ${c:0:4} differs from ${commit_to_compare_with:0:4} by $diff_count lines
  if [ $diff_count -lt $minimal_diff_count ]
  then
    most_similar_commit=$c
    minimal_diff_count=$diff_count
  fi
done

echo
echo Most similar commit to $commit_to_compare_with is $most_similar_commit

这是我得到的输出:

Found 5 commits in the range 1cb1d..e172

e172 differs from d67e by 45 lines
1431 differs from d67e by 26 lines
20e2 differs from d67e by 347 lines
fb80 differs from d67e by 347 lines
8d67 differs from d67e by 360 lines

Most similar commit to d67e is 14310bc0cf69967d4781e0aec2fd2cca21d72ac6

【讨论】:

    【解决方案2】:

    看起来gitxref 可以做到这一点,它是为完全相同的用例编写的(剥离了历史的供应商 tarball)。

    【讨论】:

      猜你喜欢
      • 2010-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-27
      • 2010-10-24
      • 1970-01-01
      相关资源
      最近更新 更多