列出GIT历史记录中给定行号的所有版本 [英] List all the versions of a given line number in the GIT history

查看:52
本文介绍了列出GIT历史记录中给定行号的所有版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Git中是否可以通过行号列出文件中给定行的所有先前版本?

Is it possible in Git to list all the previous versions of a given line in a file by the line number?

之所以有用,是因为它能够根据记录的堆栈跟踪报告更轻松地解决问题.

The reason why I would find it useful is to be able to easier troubleshoot a problem based on logged stack trace report.

即我在给定文件的第100行记录了未定义的方法异常.该文件包含在大量提交中,这些提交导致即使没有对其进行任何更改,给定的行也可能在文件中上下移动.

i.e. I have a undefined method exception logged at a line 100 of a given file. The file is included in plenty of commits which caused the given line might have 'traveled' up and down the file even without any changes made to it.

我如何在最近的x次提交中打印出给定文件的第100行的内容?

How would I print out the content of line 100 of a given file across last x commits?

推荐答案

这将对个有意义的修订版 git blame 进行调用,以显示行 $ LINE $ FILE 的code>:

This will call git blame for every meaningful revision to show line $LINE of file $FILE:

git log --format=format:%H $FILE | xargs -L 1 git blame $FILE -L $LINE,$LINE

通常,每行的开头都会显示修订号.您可以追加

As usual, the blame shows the revision number in the beginning of each line. You can append

| sort | uniq -c

以获取汇总结果,例如更改此行的提交列表.(不完全是,如果仅移动了代码,则对于行的不同内容,这可能会两次显示相同的提交ID.要进行更详细的分析,您必须对 git blame进行滞后比较相邻提交的结果.有人吗?)

to get aggregated results, something like a list of commits that changed this line. (Not quite, if code only has been moved around, this might show the same commit ID twice for different contents of the line. For a more detailed analysis you'd have to do a lagged comparison of the git blame results for adjacent commits. Anyone?)

这篇关于列出GIT历史记录中给定行号的所有版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆