Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In a git diff, can I show only deletions that aren't followed by an addition?

Tags:

git

diff

I'd like to be able to show deletions in git diff that aren't followed by an addition. That is, only show - lines that aren't followed by + lines. Is that possible?

like image 435
qleguennec Avatar asked Oct 26 '25 14:10

qleguennec


2 Answers

git diff | awk '/^@/{ if(s) print p; s = 1; p="" } 
    s == 1 && /^\+/ { s = 0 } 1 {p = sprintf("%s\n%s", p, $0)} 
    END { if (s) print p }' s=2
like image 129
William Pursell Avatar answered Oct 29 '25 03:10

William Pursell


git diff --numstat | awk '/^0/ {print $3}'

From the git-diff manpage:

The --numstat option gives the diffstat(1) information but is designed for easier machine consumption. An entry in --numstat output looks like this:

1       2       README
3       1       arch/{i386 => x86}/Makefile

That is, from left to right:

  1. the number of added lines;

  2. a tab;

  3. the number of deleted lines;

  4. a tab;

  5. pathname (possibly with rename/copy information);

  6. a newline.

like image 38
Geremia Avatar answered Oct 29 '25 04:10

Geremia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!