git finding duplicate commits (by patch-id)

后端 未结 7 1804
天命终不由人
天命终不由人 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:17

    The nifty command suggested by bsb requires a couple of small tweaks:

    (1) Instead of git show, which runs git diff-tree --cc, the command should use

        git diff-tree -p
    

    Otherwise git patch-id generates spurious null SHA1 hashes.

    (2) When the pipe to xargs is used, xargs should have the -L 1 argument. Otherwise a triplicated commit will not be paired with an equivalent commit.

    Here's an alias to go in ~/.gitconfig:

    dup = "!f() { for c in $(git rev-list HEAD); do git diff-tree -p $c | git patch-id; done | perl -anle '($p,$c)=@F;print \"$c $s{$p}\" if $s{$p};$s{$p}=$c' | xargs -L 1 git show -s --oneline; }; f" # "git dup" lists duplicate commits
    

提交回复
热议问题