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

前端 未结 12 2055
清酒与你
清酒与你 2020-11-30 22:13

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         


        
12条回答
  •  南笙
    南笙 (楼主)
    2020-11-30 22:58

    I had this same problem so I wrote a gawk script that changes the output of git diff to prepend the line number for each line. I find it useful sometimes when I need to diff working tree, although it's not limited to that. Maybe it is useful to someone here?

    $ git diff HEAD~1 |showlinenum.awk
    diff --git a/doc.txt b/doc.txt
    index fae6176..6ca8c26 100644
    --- a/doc.txt
    +++ b/doc.txt
    @@ -1,3 +1,3 @@
    1: red
    2: blue
     :-green
    3:+yellow
    

    You can download it from here:
    https://github.com/jay/showlinenum

提交回复
热议问题