How to get working copy size in git?

I want to calculate the total size of a working copy of my current highlighted branch in git (only files with a version, not ignored files or files that are not yet descendants of HEAD). I have currently tried this:

$ git ls-files | du -k | cut -f1 | awk '{total += $1} END {print total}'

However, it takes an insane amount of time and prints out a number that doesn't make sense:

29800260

I'm not sure what this number is. If this requires a faster or more accurate team, please let me know.

+4
source share
2 answers

You are on the right track, but using backticks instead of pipe.

du -k `git ls-files` | awk '{total += $1} END {print total}'

If you need to worry about spaces, then git ls-filesthey xargscan and do speak in zeros:

git ls-files -z | xargs -0 du -k | awk '{total += $1} END {print total}'

, git ls-files | -, du -k | . , !

+2

, du , . . , 1- 4 , .

, :

git ls-tree -r -l HEAD | cut -d' ' -f 4- | awk '{s+=$1} END {printf "%.0f\n", s}'

blob, Git, . , du.

0

Source: https://habr.com/ru/post/1529901/


All Articles