From a8d9e18c366f2588d244fc2b03ce8880308aaf71 Mon Sep 17 00:00:00 2001 From: Michael Campagnaro Date: Mon, 23 Dec 2024 19:58:11 -0500 Subject: [PATCH] Add a git alias to see size of tracked files --- .aliases | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/.aliases b/.aliases index fa4f2e2..6625ef1 100644 --- a/.aliases +++ b/.aliases @@ -1276,6 +1276,19 @@ git_create_stash_patch() { printf "${BOLD}${YELLOW}Created $file for stash@{$stashNum}.${NORMAL}\n" } +git_print_tracked_file_sizes() { + git ls-tree -r -l HEAD | sort -k 4 -nr | awk '{ + sha = substr($3, 1, 7); # Truncate the commit SHA to 7 characters + if ($4 >= 1024 * 1024) { + printf "%s sha:%s %06.2f MB %s\n", $2, sha, $4 / 1024 / 1024, $5 + } else if ($4 >= 1024) { + printf "%s sha:%s %06.2f KB %s\n", $2, sha, $4 / 1024, $5 + } else { + printf "%s sha:%s %04d B %s\n", $2, sha, $4, $5 + } + }' +} + alias am='git commit --amend' alias amno='git_amend_nocheckin' alias ama='git commit --amend -C head --author' @@ -1338,8 +1351,8 @@ alias gmffm='git merge --ff-only master' alias gmffs='git merge --ff-only --squash' alias gmtheirs='git merge -Xtheirs' alias gp='git push' -alias gpa='git push --all && echo "pushing tags..." && git push --tags' -alias gpaf='git push --all -f && echo "pushing tags..." && git push --tags -f' +alias gpa='echo "pushing all branches..." && git push --all && echo "pushing tags..." && git push --tags' +alias gpaf='echo "force pushing all branches..." && git push --all -f && echo "force pushing tags..." && git push --tags -f' alias gpf='git push -f' alias gpff='git pull --ff-only' alias gplu='git pull --set-upstream origin HEAD' @@ -1402,6 +1415,7 @@ alias gx='git reset --hard' alias gxx='git reset --hard HEAD~1' alias gxom='git reset --hard origin/master' alias gstats='echo "Total commits: $(git rev-list HEAD --count)"; echo "\nAuthor breakdown:"; git shortlog | grep -E "^[^ ]"' +alias gsize='git_print_tracked_file_sizes' alias gwip="git add . && git commit -m \"WIP\"" ####################################################################################################