如何计算git变动的文件大小

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash
# The tool to get the total size of autoupdate
# by Dannyhe
function NotSupport()
{
echo "Not support $OSTYPE"
exit -1
}
function main()
{
echo "os: $OSTYPE"
echo "size:"
if [[ "$OSTYPE" == "linux-gnu" ]]; then
NotSupport
elif [[ "$OSTYPE" == "darwin"* ]]; then
# Mac OSX
git log --name-status -1 | grep -E '^[A-Z]\b' | sort -k 2,2 -u | grep -E "M|A" | awk '{print $2}' | xargs stat -f "%z" | awk '{t+=$0}END{print t/(1024*1024)" Mb"}'
elif [[ "$OSTYPE" == "cygwin" ]]; then
# POSIX compatibility layer and Linux environment emulation for WindowsNotSupport
NotSupport
elif [[ "$OSTYPE" == "msys" ]]; then
# Lightweight shell and GNU utilities compiled for Windows (part of MinGW)
git log --name-status -1 | grep -E '^[A-Z]\b' | sort -k 2,2 -u | grep -E "M|A" | awk '{print $2}' | xargs du -b | awk '{t+=$0}END{print t/(1024*1024)" Mb"}'
elif [[ "$OSTYPE" == "freebsd"* ]]; then
NotSupport
else
NotSupport
fi
}
main