Skip to content

Instantly share code, notes, and snippets.

@ento
Created May 15, 2025 02:22
Show Gist options
  • Save ento/83738ba362356650f424b76e39ff93b7 to your computer and use it in GitHub Desktop.
Save ento/83738ba362356650f424b76e39ff93b7 to your computer and use it in GitHub Desktop.
git alias for calculating the number of lines changed since the 'parent' branch
[alias]
# Alias to get the nearest parent; adapetd from https://stackoverflow.com/a/17843908
parent = "!git show-branch 2>/dev/null | grep '*' | grep -v \"$(git rev-parse --abbrev-ref HEAD)\" | head -n1 | sed 's/[^\\[]*\\[\\([^\\[]*\\)\\].*/\\1/' | sed 's/[\\^~].*//' #"
# Print the number of lines changed sicne the parent branch. e.g. branch-name +10 -10
size = "!echo -n \"$(git parent) \"; git diff $(git parent)...HEAD --numstat | awk '{ additions+=$1; deletions+=$2 } END { print \"\\033[32m\" \"+\" additions \"\\033[0m\" \" \" \"\\033[31m\" \"-\" deletions }' #"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment