Created
October 18, 2012 16:15
-
-
Save nahurst/3912888 to your computer and use it in GitHub Desktop.
Find the difference between a file and X changes ago
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/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