Skip to content

Instantly share code, notes, and snippets.

@hrishikeshs
Created March 22, 2022 13:23
Show Gist options
  • Save hrishikeshs/eee0f61e89cfd83cec4b4f3caf898490 to your computer and use it in GitHub Desktop.
Save hrishikeshs/eee0f61e89cfd83cec4b4f3caf898490 to your computer and use it in GitHub Desktop.
git diff output that shows only the deleted lines from your diff.
#!/bin/bash
#
# Written by Hrishikesh S
#
# Filters the output of git diff by showing you only the lines that are deletions.
# It doesn't display additions.
#
# Put this anywhere on your $PATH (~/bin is recommended). Then git will see it
# and you'll be able to do `git diff-deleted`.
#
set -e
# the stuff "\030" and stuff is for colorized output, ignore it.
git diff | awk '{if ($1 ~ /^[-]{1}/) {print "\033[31m" $0 "\033[0m"} else if($1 ~ /^[-]{3}/) {print "\033[1;32m" $0 "\033[0m"}}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment