-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgitFindLargestFiles.sh
More file actions
50 lines (43 loc) · 1.7 KB
/
gitFindLargestFiles.sh
File metadata and controls
50 lines (43 loc) · 1.7 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
# From: https://stackoverflow.com/questions/10622179/how-to-find-identify-large-files-commits-in-git-history
# To delete found files: https://stackoverflow.com/a/43640996
source @includes.sh
echo '###################################################'
echo '# Description: Find largest files in a git repo'
echo '# Usage: $ ./gitFindLargestFiles.sh /git/repo/path 30'
echo '# Param 1: Git repo directory'
echo '# Param 2 [Optional]: Numer of files'
echo '###################################################'
echoNewline
################################################################################
################################################################################
# check parameters
if [[ $1 == "" ]] ; then
echoError '1st arg must be a git repo path'
exit 1
fi
numFiles="10"
if [[ $2 -eq 0 ]] ; then
echoInfo "[Optional]: Using default numFiles ${numFiles}"
else
numFiles=$2
echoInfo "[Optional]: Using user-defined numFiles ${numFiles}"
fi
################################################################################
################################################################################
# get filename
repoDir=$1
echoInfo "Listing ($numFiles) large files in repo: $repoDir"
# find files in history
cd $repoDir
git rev-list --objects --all \
| git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' \
| sed -n 's/^blob //p' \
| sort --numeric-sort --key=2 \
| cut -c 1-12,41- \
| tail -$numFiles \
| numfmt --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest
cd -
################################################################################
################################################################################
# complete