Created
July 6, 2025 19:01
-
-
Save mikealche/af005cc99afd675731e802a2f09f6df4 to your computer and use it in GitHub Desktop.
Check out a git repo from its origins and step through it's updates
This file contains hidden or 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/bash | |
| # Git Stepper - Navigate through commits chronologically | |
| # Usage: ./git-stepper.sh | |
| # Get all commits in reverse chronological order (oldest first) | |
| commits=($(git log --reverse --pretty=format:"%H")) | |
| total_commits=${#commits[@]} | |
| if [ $total_commits -eq 0 ]; then | |
| echo "No commits found in this repository." | |
| exit 1 | |
| fi | |
| current_index=0 | |
| show_commit() { | |
| local commit=${commits[$current_index]} | |
| echo "==========================================" | |
| echo "Commit $(($current_index + 1)) of $total_commits" | |
| echo "==========================================" | |
| git show --stat $commit | |
| echo | |
| echo "Files changed:" | |
| git diff-tree --no-commit-id --name-only -r $commit | |
| echo | |
| } | |
| navigate() { | |
| while true; do | |
| show_commit | |
| echo "Commands:" | |
| echo " n/next - Next commit" | |
| echo " p/prev - Previous commit" | |
| echo " c/checkout - Checkout this commit" | |
| echo " d/diff - Show full diff" | |
| echo " l/log - Show commit message" | |
| echo " q/quit - Quit" | |
| echo " h/help - Show this help" | |
| echo | |
| read -p "Enter command: " cmd | |
| case $cmd in | |
| n|next) | |
| if [ $current_index -lt $((total_commits - 1)) ]; then | |
| current_index=$((current_index + 1)) | |
| else | |
| echo "Already at the last commit." | |
| fi | |
| ;; | |
| p|prev) | |
| if [ $current_index -gt 0 ]; then | |
| current_index=$((current_index - 1)) | |
| else | |
| echo "Already at the first commit." | |
| fi | |
| ;; | |
| c|checkout) | |
| git checkout ${commits[$current_index]} | |
| echo "Checked out commit ${commits[$current_index]}" | |
| ;; | |
| d|diff) | |
| git show ${commits[$current_index]} | |
| ;; | |
| l|log) | |
| git log -1 --pretty=format:"%H%n%an <%ae>%n%ad%n%s%n%b" ${commits[$current_index]} | |
| echo | |
| ;; | |
| q|quit) | |
| echo "Returning to original branch..." | |
| git checkout - | |
| break | |
| ;; | |
| h|help) | |
| # Help is shown by default | |
| ;; | |
| *) | |
| echo "Unknown command. Type 'h' for help." | |
| ;; | |
| esac | |
| echo | |
| done | |
| } | |
| echo "Git Stepper - Navigate through $total_commits commits" | |
| echo "Starting from the first commit..." | |
| navigate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment