Kasun Siyambalapitiya
Kasun Siyambalapitiya

Reputation: 4403

How to identify line modifications separately from deletions in git log

In a certain file, I need to count the exact no of lines being Modified from one commit to another. If I do a git log it indicate me something like this,

10 10 modules/p2-profile-gen/pom.xml 2 2 pom.xml

4 4 pom.xml

1 0 modules/distribution/pom.xml

1 1 pom.xml

1 1 pom.xml

10 8 pom.xml

29 28 modules/p2-profile-gen/pom.xml 175 4 pom.xml

up to the second line of

1 1 pom.xml

can be easily understood, but from then how do we know for sure that they are just modifications or deletions. For example,

29 28 modules/p2-profile-gen/pom.xml 175 4 pom.xml

how do we know which is correct from

  1. 29 new additions and 28 separate deletions
  2. 28 modifications and 1 new addition

is there any options to be used with the git log or is there any other way? thanks in advance

Upvotes: 1

Views: 244

Answers (2)

Kasun Siyambalapitiya
Kasun Siyambalapitiya

Reputation: 4403

This cannot be achieved with git log, the only way to achieve this is through git diff but in it also it does only provide the no of line additions and deletions, there is no way to identify exactly the no of lines modified. This is because git provide the diff output in the unified view as default not in the context view. You can learn about unified view from here and context view from here.

So if we get the output of git diff in the context form, the lines that are added, deleted and modified can easily be identified as additions are shown with "+", deletions with "-" and modifications with "!". For that we need to use the git difftool, the following code works

git difftool -y -x "diff -c" <commit1> <commit2>

Upvotes: 1

Pockets
Pockets

Reputation: 1264

I think what you're looking for is git diff:

git diff --stat <old-commit> <new-commit> -- <filename>

e.g.

$ git diff --stat a54873b a6addbd -- Foo.cpp
 Foo.cpp | 42 +++++++++++++++++++++++++++++++++++-------
 1 file changed, 35 insertions(+), 7 deletions(-)

Upvotes: 0

Related Questions