Skip to content

Instantly share code, notes, and snippets.

@arnaudcourtecuisse
Created October 21, 2021 10:59
Show Gist options
  • Save arnaudcourtecuisse/dc0f758ee5ec38e7fd6b27b707ccf554 to your computer and use it in GitHub Desktop.
Save arnaudcourtecuisse/dc0f758ee5ec38e7fd6b27b707ccf554 to your computer and use it in GitHub Desktop.
Squash and merge basic implementation
fancy_branch_descr() {
local fancy=${1//[-_]/ }
echo ${fancy^}
}
create_commit_message() {
local base=$1 branch=$2
fancy_branch_descr $branch
git log --pretty=format:"%n* %s" ${base}..${branch}
}
squash_n_merge() {
local base=$1 branch=$2 msg_file=$(mktemp) head
create_commit_message $base $branch > $msg_file
# Squash commits
git checkout --detach $branch
git reset --soft $base
git commit -m "$(cat $msg_file)"
head=$(git rev-parse HEAD)
rm $msg_file
# Merge
git checkout $base
git merge $head
}
# If `branch` was based on `squashed` and `squashed` was squashed and merged into `base`,
# this allows you to rebase `branch` on `base` without the `squashed` commits
rerebase() {
local base=$1 squashed=$2 branch=$3
git rebase --onto $base $squashed $branch
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment