git finding duplicate commits (by patch-id)

后端 未结 7 1812
天命终不由人
天命终不由人 2020-12-16 02:05

I\'d like a recipe for finding duplicated changes. patch-id is likely to be the same but the commit attributes may not be.

This seems to be an intended use of patch-

7条回答
  •  忘掉有多难
    2020-12-16 02:14

    I have a draft that works on a toy repo, but as it keeps the patch->commit map in memory it might have problems on large repos:

    # print commit pairs with the same patch-id
    for c in $(git rev-list HEAD); do \
        git show $c | git patch-id; done \
    | perl -anle '($p,$c)=@F;print "$c $s{$p}" if $s{$p};$s{$p}=$c'
    

    The output should be pairs of commits with the same patch-id (3 duplicates A B C come out as "A B" then "B C").

    Change the git rev-list command to restrict the commits checked:

    git log --format=%H HEAD somefile
    

    Append "| xargs git show" to view the commits in detail, or "| xargs git show -s --oneline" for a summary:

    0569473 add 6-8
    5e56314 add 6-8 again
    bece3c3 comment
    e037ed6 add comment again
    

    It turns out patch-id didn't work in my original case as there were additional changes in that later commit. "git log -S" was more useful.

提交回复
热议问题