Created
October 21, 2021 10:59
-
-
Save arnaudcourtecuisse/dc0f758ee5ec38e7fd6b27b707ccf554 to your computer and use it in GitHub Desktop.
Squash and merge basic implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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