【问题标题】:How do you do a `git blame` from the command line on one line of code that I am interested in?你如何从命令行对我感兴趣的一行代码执行“git blame”?
【发布时间】:2015-05-26 02:37:53
【问题描述】:

基本上我想要做的就是我们通常使用网络界面做的同样的事情。我知道如何使用 web 界面比如 bitbucket 或 github 来做 git blame,但是你如何使用 git CLI 来做同样的事情呢?到目前为止,我到目前为止:

  1. git grep <line of code that I am interested to see the blame>。获取文件列表,然后找到我感兴趣的文件。
  2. git blame <on file of interest>。显示谁做了什么并提交了哈希。
  3. 无法弄清楚这部分...我看到了我感兴趣的散列,我如何在那个提交散列上查看完整的提交日志?

【问题讨论】:

    标签: git command-line


    【解决方案1】:

    我在发布此内容后偶然发现了此http://zsoltfabok.com/blog/2012/02/git-blame-line-history/,因此我将在此处发布此内容以供参考。步骤是:

    1. 找到您感兴趣的行号,然后执行git blame -L <starting line number>,<ending line number> <filename>。 (即行号以逗号分隔,没有空格)
    2. git show <commit hash> 将向您展示您需要了解的内容。

    【讨论】:

    • 如果输出应该只包含一行,它必须是-L <line number>,<line number>-L <line number>,+1。否则输出包含从给定行号开始直到文件结尾的所有内容。
    • 谢谢,我已经添加了。
    猜你喜欢
    • 2012-06-17
    • 2012-03-20
    • 2021-01-05
    • 1970-01-01
    • 1970-01-01
    • 2010-11-18
    • 2012-07-08
    • 2010-10-29
    • 2021-10-27
    相关资源
    最近更新 更多