Skip to content

Instantly share code, notes, and snippets.

@michaeloyer
Last active June 3, 2021 20:24
Show Gist options
  • Save michaeloyer/ad89832e4ed61ab6d5337cce0bd66ba3 to your computer and use it in GitHub Desktop.
Save michaeloyer/ad89832e4ed61ab6d5337cce0bd66ba3 to your computer and use it in GitHub Desktop.
Git Rebase Onto explained with a script you can run on an empty directory
git init
git checkout -b original
git commit --allow-empty -m 'Commit 1'
git commit --allow-empty -m 'Commit 2'
git commit --allow-empty -m 'Commit 3 (third)'
git tag third
git commit --allow-empty -m 'Commit 4'
git commit --allow-empty -m 'Commit 5'
git tag fifth
git commit --allow-empty -m 'Commit 6 (sixth)'
git commit --allow-empty -m 'Commit 7'
git commit --allow-empty -m 'Commit 8'
git checkout -b rebased
git commit --allow-empty -m 'Test Commit 1'
git commit --allow-empty -m 'Test Commit 2'
git commit --allow-empty -m 'Test Commit 3'
git rebase --onto third fifth
git log --format='%C(bold blue)%s' original
git log --format='%C(bold yellow)%s' rebased
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment