Skip to content

Instantly share code, notes, and snippets.

@d4hines
Created January 3, 2022 16:33
Show Gist options
  • Save d4hines/92462bd08506a8fed628662aa93f16a9 to your computer and use it in GitHub Desktop.
Save d4hines/92462bd08506a8fed628662aa93f16a9 to your computer and use it in GitHub Desktop.
iterate commits one by one
#!/usr/bin/env bash
# Used to go through each commit in a repo one by one
# for exploratory purposes.
git reset --hard HEAD
git clean -xfd
INDEX=$(cat /tmp/index)
INDEX=$(($INDEX + 1))
echo $INDEX > /tmp/index
TOTAL=$(git rev-list --branches main | wc -l)
NEXT=$(($TOTAL - $INDEX))
COMMIT=$(git rev-list --branches main | sed "${NEXT}q;d")
git co $COMMIT
git reset --soft HEAD~1
echo "==== Now showing commit $INDEX/$TOTAL ===="
git rev-list --pretty=medium --max-count=1 $COMMIT | tee /tmp/message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment