Last active
February 5, 2020 21:22
-
-
Save jouni-kantola/5275d040a95fb761486fa0481f2743bc to your computer and use it in GitHub Desktop.
Replay git commits
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
#!/bin/sh | |
# Remember current branch | |
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) | |
# Temp branch used for replaying history | |
TEMP_BRANCH=__tmp-replay-git-commits | |
# Checkout temp branch | |
git checkout -b $TEMP_BRANCH | |
# List commits in chronological order | |
# Default to HEAD if missing argument | |
COMMITS=$(git rev-list ${1:-HEAD}..${2:-HEAD} | tac) | |
for COMMIT in $COMMITS | |
do | |
# Move head to old commit | |
git checkout $COMMIT | |
# Sleep before moving to newer | |
# Default to 1 second | |
sleep ${3:-1} | |
done | |
# Back to current branch | |
git checkout $CURRENT_BRANCH | |
# Cleanup temp branch | |
git branch -D $TEMP_BRANCH |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An example of how the script can be used is to re-apply all commits in chronological order while recording the screen.