Skip to content

Instantly share code, notes, and snippets.

@ticky
Last active August 2, 2017 09:28
Show Gist options
  • Save ticky/2db4f71449fc05fc6a807996e20224c2 to your computer and use it in GitHub Desktop.
Save ticky/2db4f71449fc05fc6a807996e20224c2 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# git-shiftbase
# tool for progressive rebasing of a feature branch
set -euo pipefail
GIT_SHIFTBASE=$(basename $0)
short_sha_for() {
git rev-parse --short $1
}
if [[ $# = 0 ]]; then
echo "usage: $GIT_SHIFTBASE <branch>"
echo
echo "Parameters:"
echo " branch the branch on which to rebase the current branch."
echo
echo "Output filename is the original filename with -28p8 and the number of iterations appended."
exit
fi
GIT_SHIFTBASE_MERGE_BASE="$(git merge-base "$1" HEAD)"
GIT_SHIFTBASE_REVS_SINCE=( $(git rev-list --reverse --merges --first-parent "$GIT_SHIFTBASE_MERGE_BASE...$1") )
GIT_SHIFTBASE_REV_COUNT=${#GIT_SHIFTBASE_REVS_SINCE[@]}
echo "$GIT_SHIFTBASE: found $GIT_SHIFTBASE_REV_COUNT merge commits found since $(short_sha_for $GIT_SHIFTBASE_MERGE_BASE)"
read -p "$GIT_SHIFTBASE: Do you want to continue? " -n 1 -r
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo ""
echo "fair enough. everything's still where it was!"
exit 0
fi
echo "Let's do this. Good luck! <3"
rev_index=0
for revision in "${GIT_SHIFTBASE_REVS_SINCE[@]}"; do
echo "$GIT_SHIFTBASE: trying $revision (revision $(($rev_index + 1))/$GIT_SHIFTBASE_REV_COUNT)..."
git rebase "$revision"
rev_index=$(($rev_index + 1))
done

The MIT License (MIT)

Copyright © 2017 Jessica Stokes

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment