Git line number before and after

I have some capital commits in my git repository. Some of the commits are tagged with git. Consider an example:

commits:  Master -> Master -> Master -> Master
tags:       v1        v2        v3       HEAD

Now I have a report that in version v2 there is an error in the file name of the file on line 45.

Is there a way to get the line number based on HEAD and line number 45 in v2?

git diff HEAD v2 filename show me the differences, but what I really want is just the “new” line number.

To be more specific, if I added 3 lines when fixing v3 and deleting 1 line in the last (HEAD) commit, some command gitshould bring me 45 + 3 - 1 = 47. Are there any?

+3
source share
1 answer

Further easier IMHO will use git blame:

git blame $ref -L'/search_pattern/,+1' filename(s)

Full example in my zfs-fuse repository:

$ git for-each-ref --format='%(refname)' -- refs/heads |
       while read ref; 
            do git blame $ref -L'/push/,+1' zfs_operations.c; 
       done

, ; , , . :

f5370a5e (Emmanuel Anne 2011-02-22 20:53:17 +0100 1492) static void push(zfsvfs_t *zfsvfs, cred_t *cred, fuse_ino_t ino, file_info_t *info, const char *buf, size_t size, off_t off)
f5370a5e (Emmanuel Anne 2011-02-22 20:53:17 +0100 1512) static void push(zfsvfs_t *zfsvfs, cred_t *cred, fuse_ino_t ino, file_info_t *info, const char *buf, size_t size, off_t off)
f5370a5e (Emmanuel Anne 2011-02-22 20:53:17 +0100 1512) static void push(zfsvfs_t *zfsvfs, cred_t *cred, fuse_ino_t ino, file_info_t *info, const char *buf, size_t size, off_t off)

(1492 1512):

f5370a5e (Emmanuel Anne 2011-02-22 20:53:17 +0100 1512) void push (zfsvfs_t * zfsvfs, cred_t * cred, fuse_ino_t ino, file_info_t * info, const char * buf, size_t size, off_t off)

, ,

fatal: -L parameter 'push': No match

:

 -M    (detect moved lines)
 -n    (show source line number)
 -f    (show filename, especially handy with -C)
 -p / --incremental: if you want something parsed more easily in code
+3

All Articles