Skip to content

Instantly share code, notes, and snippets.

@nahurst
Created October 18, 2012 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nahurst/3912888 to your computer and use it in GitHub Desktop.
Save nahurst/3912888 to your computer and use it in GitHub Desktop.
Find the difference between a file and X changes ago
#!/usr/bin/ruby
# Finds the difference between a file and X changes ago
# gitdifflast path/to/file 2
# would be the difference between this version and two changes ago (when the file actually changed not just commits)
# this distinguishes between the last change and the last commit
# use "git diff HEAD@{1} path/to/file" or "git diff HEAD^ path/to/file" for that
file = ARGV.shift
change_increment = ARGV.shift.to_i
log_output = `git log --oneline #{file}`
diff_change_line = log_output.to_a[change_increment]
refspec = diff_change_line.split(" ").first
diff_output = `git diff #{refspec} #{file}`
puts diff_output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment