Created
September 12, 2023 17:27
-
-
Save panki/ba99ff696d9c4738a99d78214d63ea0f to your computer and use it in GitHub Desktop.
Git diff with line numbers
This file contains hidden or 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
git diff HEAD^ HEAD | awk ' | |
/^@@/ { | |
gsub(/@@|\+|\-|@@/, "", $0); | |
split($1, old, ",") | |
split($2, new, ",") | |
old_line = old[1] | |
new_line = new[1] | |
next | |
} | |
{ | |
if ($0 ~ /^(---|\+\+\+)|diff|index/) { | |
print $0; | |
} | |
else if($0 ~ /^-/) { | |
printf "-%4s %s\n", old_line, substr($0,2); | |
old_line++; | |
} else if($0 ~ /^\+/) { | |
printf "+%4s %s\n", new_line, substr($0,2); | |
new_line++; | |
} else { | |
print " ", $0; | |
old_line++; | |
new_line++; | |
} | |
}' | grep -e "^[-+]" | grep offset |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment