Created
October 28, 2022 19:38
-
-
Save HarlemSquirrel/8288aa10541be48f0a375727b93e0677 to your computer and use it in GitHub Desktop.
Show git additions/changes for the git diff from the main branch
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
## | |
# | |
# 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