Skip to content

Instantly share code, notes, and snippets.

@HarlemSquirrel
Created October 28, 2022 19:38
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 HarlemSquirrel/8288aa10541be48f0a375727b93e0677 to your computer and use it in GitHub Desktop.
Save HarlemSquirrel/8288aa10541be48f0a375727b93e0677 to your computer and use it in GitHub Desktop.
Show git additions/changes for the git diff from the main branch
##
#
# https://github.com/anolson/git_diff
require 'git_diff'
patch = `git diff main -U0 --diff-filter=AM`
diff = GitDiff.from_string(patch)
diff.files.each do |diff_file|
puts "\n#{diff_file.b_path}"
# Select diff lines that have been added/modified
diff_lines = diff_file.hunks.map(&:lines).flatten.select { |diff_line| diff_line.content.start_with?("+") }
diff_lines.each do |diff_line|
puts " #{diff_line.line_number.right.to_s.rjust(4)} #{diff_line.content} "
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment