Created
September 13, 2011 18:31
-
-
Save anonymous/1214610 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
# Walks up and down revisions in a git repo. | |
# Usage: | |
# git walk next | |
# git walk prev | |
case ARGV[0] | |
when "next" | |
rev_list = `git rev-list --children --all` | |
refs = rev_list.scan(/[a-z0-9]{40}(?= )/) | |
refs.unshift(rev_list[/[a-z0-9]{40}/]) | |
refs.reverse! | |
head = `git rev-parse HEAD`.chomp | |
ref_for_next_commit = refs[refs.index(head) + 1] | |
if ref_for_next_commit | |
puts `git checkout #{ref_for_next_commit}` | |
else | |
puts "You're already on the latest commit." | |
end | |
when "prev" | |
puts `git checkout HEAD^` | |
else | |
puts "Usage: git-walk next|prev" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment