Skip to content

Instantly share code, notes, and snippets.

@serious-angel
Last active January 25, 2026 11:51
Show Gist options
  • Select an option

  • Save serious-angel/a3a847c94e13e034e66ad21d6caddb9d to your computer and use it in GitHub Desktop.

Select an option

Save serious-angel/a3a847c94e13e034e66ad21d6caddb9d to your computer and use it in GitHub Desktop.
[WIP] Diff size between two Git references
$ ls -lA '~/.local/exec-scripts/';
total 4
-rwxrwxr-x 1 user user 927 Jan 25 13:20 git-file-size-diff.sh
$ export PATH="${PATH}${PATH:+:}${HOME}/.local/exec-scripts";

$ git log;
commit 5fa4793a2d2d70ad08b85387b41020f1fcc2d19e (grafted, HEAD)
Author: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date:   Sun Dec 7 06:18:54 2025 +0900

    Linux 6.6.119

    Link: https://lore.kernel.org/r/20251203152336.494201426@linuxfoundation.org
    Tested-by: Florian Fainelli <florian.fainelli@broadcom.com>
    Tested-by: Hardik Garg <hargar@linux.microsoft.com>
    Tested-by: Shuah Khan <skhan@linuxfoundation.org>
    Tested-by: Peter Schneider <pschneider1968@googlemail.com>
    Tested-by: Jon Hunter <jonathanh@nvidia.com>
    Tested-by: Ron Economos <re@w6rz.net>
    Tested-by: Mark Brown <broonie@kernel.org>
    Tested-by: Linux Kernel Functional Testing <lkft@linaro.org>
    Tested-by: Miguel Ojeda <ojeda@kernel.org>
    Tested-by: Brett A C Sheffield <bacs@librecast.net>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

$ git reflog;
5fa4793a2 (grafted, HEAD) HEAD@{0}: checkout: moving from android15-6.6-lts to 5fa4793a2d2d70ad08b85387b41020f1fcc2d19e
dda2fd289 (grafted, origin/android15-6.6-lts, android15-6.6-lts) HEAD@{1}: clone: from https://android.googlesource.com/kernel/common

$ git remote show origin;
* remote origin
  Fetch URL: https://android.googlesource.com/kernel/common
  Push  URL: https://android.googlesource.com/kernel/common
  HEAD branch: android-mainline
  Remote branch:
    android15-6.6-lts tracked
  Local branch configured for 'git pull':
    android15-6.6-lts merges with remote android15-6.6-lts
  Local ref configured for 'git push':
    android15-6.6-lts pushes to android15-6.6-lts (up to date)

$ git file-size-diff.sh 5fa4793a2 dda2fd289;
# ...
Total: 15873439 bytes ( 15.14MiB)
# Modified by Serious Angel on 2026-01-25
# Source - https://stackoverflow.com/a/10847242/5113030
# Posted by patthoyts, modified by community. See post 'Timeline' for change history
# Retrieved 2026-01-25, License - CC BY-SA 4.0
#!/bin/bash
USAGE='[--cached] [<rev-list-options>...]
Show file size changes between two commits or the index and a commit.'
SUBDIRECTORY_OK=1
. "$(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
printf 'Total: %s bytes (%s)\n' "$total" "$( numfmt --to=iec-i --suffix=B --format="%9.2f" "$total"; )";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment