Git: Find duplicate blobs (files) in this tree

后端 未结 6 2011
长发绾君心
长发绾君心 2021-02-04 03:32

This is sort of a follow-up to this question.

If there are multiple blobs with the same contents, they are only stored once in the git repository because their SHA-1\'s

6条回答
  •  囚心锁ツ
    2021-02-04 04:26

    For Windows / PowerShell users:

    git ls-tree -r HEAD | group { $_ -replace '.{12}(.{40}).*', '$1' } | ? { $_.Count -gt 1 } | select -expand Group
    

    This outputs something like:

    100644 blob 8a49bcbae578c405ba2596c06f46fabbbc331c64    filename1
    100644 blob 8a49bcbae578c405ba2596c06f46fabbbc331c64    filename2
    100644 blob c1720b20bb3ad5761c1afb6a3113fbc2ba94994e    filename3
    100644 blob c1720b20bb3ad5761c1afb6a3113fbc2ba94994e    filename4
    

提交回复
热议问题