Skip to content

Instantly share code, notes, and snippets.

Created September 13, 2011 18:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/1214610 to your computer and use it in GitHub Desktop.
Save anonymous/1214610 to your computer and use it in GitHub Desktop.
#!/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