2

I use the following command to identify the no of lines which are been modified in between 2 commits. the b26e..and the e1f5... are the commit hashes

git difftool -y -x "diff -c" b26ea5c511970d0211186c3b1e119224465ad365 e2f5104a2dd1afdc27803ead58b74cfd18ae50be

below is the output of the file

*** /tmp/n90Z9a_Testing.txt 2016-12-02 11:47:59.027168926 +0530
--- /tmp/19ymab_Testing.txt 2016-12-02 11:47:59.027168926 +0530
***************
*** 1,3 ****
  initial commit
  added new line
! added for modification
--- 1,5 ----
  initial commit
  added new line
! added for modification, this is modified.This is modified again
! after modifiying for the second time, this line is added
! This line added for complete deletion and then replace with another

from this I need to filter out only the lines that are been modified from the first commit, in simple words I need to filter only this part from the above output

*** /tmp/n90Z9a_Testing.txt 2016-12-02 11:47:59.027168926 +0530
--- /tmp/19ymab_Testing.txt 2016-12-02 11:47:59.027168926 +0530
***************
*** 1,3 ****
  initial commit
  added new line
! added for modification

How can I filter out it, thanks in advance

Kasun Siyambalapitiya
  • 3,956
  • 8
  • 38
  • 58
  • Why don't you use `git diff ` only? – Berkay92 Dec 02 '16 at 06:58
  • 1
    @Berkay92 then the `unified` output is given which only has the additions and deletions. in the `unified` format we can't identify the actual no of lines that is been modified. for ex: 28 additions and 27 deletions shown in `diff` it could be the result of 1) 28 new additions and 27 deletions 2) 27 modificatins and one new line and etc... – Kasun Siyambalapitiya Dec 02 '16 at 07:14

2 Answers2

1

If this is just about selecting lines between two markers, you can use sed:

sed -n -e "/^\*\*\*/,/^---/{ /^---/d; p; }"

That is:

git difftool -y -x "diff -c" <shaX> <shaY> | sed -n -e "/^\*\*\*/,/^---/{ /^---/d; p; }"

That will print everything between '***' (included) and '---' (excluded)

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

try this out

git difftool -y -x "diff -c" <commitHash1> <commithash2> | awk '/\*\*\*/{flag=1}/---/{print;flag=0}flag'

To see more examples of selecting lines between 2 marker patterns with awk see this

Community
  • 1
  • 1
Kalanka
  • 1,019
  • 2
  • 18
  • 31