Skip to content

Instantly share code, notes, and snippets.

@darktef
Last active September 20, 2018 20:23
Show Gist options
  • Save darktef/5e3da351c9b80cb802822cfcb0c84a10 to your computer and use it in GitHub Desktop.
Save darktef/5e3da351c9b80cb802822cfcb0c84a10 to your computer and use it in GitHub Desktop.
Ruby - Grab the commit history of all related files
results = []
file_names = `find . -print | grep '.*referral.*'`.split("\n");nil
file_names.each do |name|
output = `git log --follow --pretty=format:'{"commit": "%H","author": "%aN <%aE>","date": "%ad","message": "%f"},' -- #{name}`
results.concat(JSON.parse('[' + output.gsub("\n", '')[0..-2] + ']'))
end
mapping = {}
results.each do |res|
next if mapping[res['commit']]
mapping[res['commit']] = res
end
sorted_mapping = mapping.sort_by { |key,val| Date.strptime(val["date"], "%a %b %d %H:%M:%S %Y %z") }
File.open("related_commits.json","w") do |f|
f.write(sorted_mapping.to_json)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment