Skip to content

Instantly share code, notes, and snippets.

@jouni-kantola
Last active February 5, 2020 21:22
Show Gist options
  • Save jouni-kantola/5275d040a95fb761486fa0481f2743bc to your computer and use it in GitHub Desktop.
Save jouni-kantola/5275d040a95fb761486fa0481f2743bc to your computer and use it in GitHub Desktop.
Replay git commits
#!/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
@jouni-kantola
Copy link
Author

An example of how the script can be used is to re-apply all commits in chronological order while recording the screen.

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