How to see the file size history of a single file in a git repository?

前端 未结 8 1653
遇见更好的自我
遇见更好的自我 2020-12-03 06:52

Is there anyway to see how a file\'s size has changed through time in a git repository? I want to see how my main.js file (which is the combination of several files and mini

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-03 07:27

    You can use either git ls-tree -r -l to get the blob size at given revision, e.g.

    $ git ls-tree -r -l v1.6.0 gitweb/README
    100644 blob 825162a0b6dce8c354de67a30abfbad94d29fdde   16067    gitweb/README
    

    The blob size in this example is '16067'. The disadvantage of this solution is that git ls-tree can process only one revision at once.

    You can use instead git cat-file --batch-check < instead, feeding it blob identifiers. If location of file didn't change through history (file was not moved), you can use git rev-list -- to get list of revisions touching given path, translate them into names of blobs using : extended SHA-1 syntax (see git-rev-parse manpage), and feed it to git cat-file. Example:

    $ git rev-list -5 v1.6.0 -- gitweb/README | 
      sed -e 's/$/:gitweb\/README/g' |
      git cat-file --batch-check
    825162a0b6dce8c354de67a30abfbad94d29fdde blob 16067
    6908036402ffe56c8b0cdcebdfb3dfacf84fb6f1 blob 16011
    356ab7b327eb0df99c0773d68375e155dbcea0be blob 14248
    8f7ea367bae72ea3ce25b10b968554f9b842fffe blob 13853
    8dfe335f73c223fa0da8cd21db6227283adb95ba blob 13801
    

提交回复
热议问题