-
-
Save jvns/0f45c910ea2d255c6e130299c99c3123 to your computer and use it in GitHub Desktop.
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
# very VERY crappy version of `git rebase` that assumes that there are no merge conflicts. | |
# the goal is to try to show the relationship between "rebase" and "merge" by | |
# showing how you can implement `git rebase` using repeated `git merge`s into a copy of the target branch | |
set -euo pipefail | |
TARGET=$1 | |
CURRENT=$(git rev-parse --abbrev-ref HEAD) | |
# Make a copy of the target branch to work in | |
git checkout -b temp-rebase-branch $TARGET | |
# Cherry pick commits onto the target branch, one at a time | |
for COMMIT in $(git rev-list --reverse --topo-order $TARGET..$CURRENT); do | |
git merge --no-commit --no-ff $COMMIT | |
git reset HEAD | |
git commit -a -C $COMMIT | |
done | |
# Force the branch we're rebasing to point at our temp rebase branch | |
git branch -f $CURRENT temp-rebase-branch | |
# Go back to the current branch | |
git checkout $CURRENT | |
# Delete the temporary branch | |
git branch -d temp-rebase-branch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment