Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

216
Visualizações
Get file size of a git commit without a tmp file

I've answered this question, suggesting using git hooks, but frankly, I'M not fully satisfied with the second part, since creating a temporary file just to get the size of the commit looks redundant and ugly. Is there a way to get the size directly? Assume the standard git implementation.

As suggested by @Cyrus, git diff --cached | wc -c is a good approximation, but it's encoding dependent.

I also tried process substitution ls -l <(git diff --cached) | awk '{print $5}' but that returns 0.

Edit: Based on @torek's answer I came up with these two solutions:

git ls-files --stage | cut -d' ' -f2 | xargs -L 1 git cat-file -s | awk '{s+=$1} END {print s}'

git diff --cached | awk -F. '/index/ {print $3}' | xargs -L 1 git cat-file -s | awk '{s+=$1} END {print s}'

The latter also handles new files.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

To get the size (in bytes) of a git object, use git cat-file -s revspec. For instance:

$ git cat-file -s HEAD:Makefile
950

Beware that this will show you the object size of a tree:

$ git cat-file -t HEAD:
tree
$ git cat-file -s HEAD:
546

For a large collection of IDs you might want to use git cat-file --batch-check (which, since git 1.8.4, now takes a format argument to select what information to print; see the documentation).

over 4 years ago · Santiago Trujillo Relatório

0

I think that git diff --cached --numstat is basically the main source of the information. For me it's not completely clear what restrictions you'd like to put on a commit but to summarize number of insertions and deletions you could use something like this:

git diff --numstat --cached | awk '
   BEGIN { insertions=0; deletions=0; }
   { insertions+=$1; deletions+=$2; }
   END { printf("inserttions=%d, deletions=%d\n", insertions, deletions); }'
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda