From 365a228b7fad651c94e5611dcba8edbe5c3cbf15 Mon Sep 17 00:00:00 2001 From: Daniel Carrillo Date: Sat, 9 Jul 2022 20:52:09 +0200 Subject: [PATCH] [git] Add git-squash function --- modules/git/functions/git-squash | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 modules/git/functions/git-squash diff --git a/modules/git/functions/git-squash b/modules/git/functions/git-squash new file mode 100644 index 0000000..1b9c142 --- /dev/null +++ b/modules/git/functions/git-squash @@ -0,0 +1,26 @@ +# +# Performs a "dirty" squash +# +# Authors: +# Daniel Carrillo +# + +# function git-squash { + +if ! is-true "$(command git rev-parse --is-inside-work-tree 2> /dev/null)"; then + print "$0: not a repository work tree: $PWD" >&2 + return 1 +elif [ -z "$2" ]; then + print "Usage: $0 \"commit message\"" >&2 + return 1 +fi + +local bbranch=$1 +local message=$2 +local cbranch=$(git branch --show-current) + +git reset $(git merge-base $bbranch $cbranch) +git add -A +git commit -m "$message" + +# }