2011-05-16 151 views
3

我有一些主提交在我的git回购。一些提交用git标签进行标记。 让我们来看看例子:之前和之后的Git行号

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

现在我有一个报告,在v2是在第45行

立案错误有什么办法基于HEAD和一线得到行号v2中的数字是45?

git diff HEAD v2 filename显示我的差异,但我真正想要的只是“新”行号。

更具体地说,如果我在v3 commit中添加3行并在最新的(HEAD)提交中删除1行,某些git命令应该会导致我45 + 3 - 1 = 47.有没有?

回答

3

更容易恕我直言,将使用git怪:

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

一个全方位的例子在我的ZFS的保险丝库:

$ 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 ):

f5370a5e(灵光安2011-02-22 20时53分17秒0100 )静态无效的push(zfsvfs_t * zfsvfs,cred_t * CRED,fuse_ino_t鲍,file_info_t *信息,为const char * buf中,为size_t大小,off_t关)

那些不匹配搜索模式的任何修订,将显示

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