Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using git diff, how can I get added and modified lines numbers?

Tags:

git

git-diff

diff

Assuming I have a text file

alex bob matrix will be removed git repo 

and I have updated it to be

alex new line here another new line bob matrix git 

Here, I have added lines number (2,3) and updated line number (6)

How can I get these line numbers info using git diff or any other git command?

like image 821
Mahmoud Khaled Avatar asked Nov 24 '11 16:11

Mahmoud Khaled


People also ask

What does ++ mean in git diff?

When viewing a combined diff, if the two files you're comparing have a line that's different from what they were merged into, you will see the ++ to represent: one line that was added does not appear in either file1 or file2.

What does git diff show you?

The git diff command shows the differences between the files in two commits or between your current repository and a previous commit. This command displays changes denotes by headers and metadata for the files that have changed.


1 Answers

git diff --stat will show you the output you get when committing stuff which is the one you are referring to I guess.

git diff --stat 

For showing exactly the line numbers that has been changed you can use

git blame -p <file> | grep "Not Committed Yet" 

And the line changed will be the last number before the ending parenthesis in the result. Not a clean solution though :(

like image 131
Sedrik Avatar answered Oct 06 '22 10:10

Sedrik