Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
366 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 :(


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...