git如何查看两次上传的差异_Git:显示两个提交之间的文件总大小差异?

Is it possible to show the total file size difference between two commits? Something like:

$ git file-size-diff 7f3219 bad418 # I wish this worked :)

-1234 bytes

I’ve tried:

$ git diff --patch-with-stat

And that shows the file size difference for each binary file in the diff — but not for text files, and not the total file size difference.

Any ideas?

解决方案

git cat-file -s will output the size in bytes of an object in git. git diff-tree can tell you the differences between one tree and another.

Putting this together into a script called git-file-size-diff located somewhere on your PATH will give you the ability to call git file-size-diff . We can try something like the following:

#!/bin/bash

USAGE='[--cached] [...]

Show file size changes between two commits or the index and a commit.'

. "$(git --exec-path)/git-sh-setup"

args=$(git rev-parse --sq "$@")

[ -n "$args" ] || usage

cmd="diff-tree -r"

[[ $args =~ "--cached" ]] && cmd="diff-index"

eval "git $cmd $args" | {

total=0

while read A B C D M P

do

case $M in

M) bytes=$(( $(git cat-file -s $D) - $(git cat-file -s $C) )) ;;

A) bytes=$(git cat-file -s $D) ;;

D) bytes=-$(git cat-file -s $C) ;;

*)

echo >&2 warning: unhandled mode $M in \"$A $B $C $D $M $P\"

continue

;;

esac

total=$(( $total + $bytes ))

printf '%d\t%s\n' $bytes "$P"

done

echo total $total

}

In use this looks like the following:

$ git file-size-diff HEAD~850..HEAD~845

-234 Documentation/RelNotes/1.7.7.txt

112 Documentation/git.txt

-4 GIT-VERSION-GEN

43 builtin/grep.c

42 diff-lib.c

594 git-rebase--interactive.sh

381 t/t3404-rebase-interactive.sh

114 t/test-lib.sh

743 tree-walk.c

28 tree-walk.h

67 unpack-trees.c

28 unpack-trees.h

total 1914

By using git-rev-parse it should accept all the usual ways of specifying commit ranges.

EDIT: updated to record the cumulative total. Note that bash runs the while read in a subshell, hence the additional curly braces to avoid losing the total when the subshell exits.

EDIT: added support for comparing the index against another tree-ish by using a --cached argument to call git diff-index instead of git diff-tree. eg:

$ git file-size-diff --cached master

-570 Makefile

-134 git-gui.sh

-1 lib/browser.tcl

931 lib/commit.tcl

18 lib/index.tcl

total 244

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值