是否有可能看到谁在git blame报告的提交之前编辑了特定的行,就像一个给定行的提交历史?
例如,我运行以下(在优秀的uncrustify项目上):
$ git blame -L10,+1 src/options.cpp
^fe25b6d (Ben Gardner 2009-10-17 13:13:55 -0500 10) #include "prototypes.h"
我如何才能找到谁在提交fe25b6d之前编辑了这一行?在提交之前是谁编辑的?
是否有可能看到谁在git blame报告的提交之前编辑了特定的行,就像一个给定行的提交历史?
例如,我运行以下(在优秀的uncrustify项目上):
$ git blame -L10,+1 src/options.cpp
^fe25b6d (Ben Gardner 2009-10-17 13:13:55 -0500 10) #include "prototypes.h"
我如何才能找到谁在提交fe25b6d之前编辑了这一行?在提交之前是谁编辑的?
当前回答
对于这个问题,一个非常独特的解决方案是使用git log,正如Andre在这里解释的那样:
git log -p -M——follow——stat——path/to/your/file
其他回答
安布尔的回答是正确的,但我觉得不清楚;语法为:
git blame {commit_id} -- {path/to/file}
注意:——用于将树状sha1与相对文件路径分开。1
例如:
git blame master -- index.html
这一切都要归功于安布尔!:)
还有递归指责。它可以安装
npm install -g recursive-blame
我使用这个小bash脚本查看一个指责历史。
第一个参数:要查看的文件
后续参数:传递给git blame
#!/bin/bash
f=$1
shift
{ git log --pretty=format:%H -- "$f"; echo; } | {
while read hash; do
echo "--- $hash"
git blame $@ $hash -- "$f" | sed 's/^/ /'
done
}
你可以提供像-L 70,+10这样的责备参数,但最好使用git责备的正则表达式搜索,因为行号通常会随着时间的推移而“改变”。
基于DavidN的回答,我想遵循重命名的文件:
LINE=8 FILE=Info.plist; for commit in $(git log --format='%h%%' --name-only --follow -- $FILE | xargs echo | perl -pe 's/\%\s/,/g'); do hash=$(echo $commit | cut -f1 -d ','); fileMayRenamed=$(echo $commit | cut -f2 -d ','); git blame -n -L$LINE,+1 $hash -- $fileMayRenamed; done | sed '$!N; /^\(.*\)\n\1$/!P; D'
参考:很好地显示文件重命名历史在git日志
基于Will Shepard的回答,他的输出将包含没有更改的提交的重复行,因此您可以按照以下方式过滤这些行(使用这个答案)
LINE=1 FILE=a; for commit in $(git rev-list HEAD $FILE); do git blame -n -L$LINE,+1 $commit -- $FILE; done | sed '$!N; /^\(.*\)\n\1$/!P; D'
注意,我删除了REVS参数,这将返回到根提交。这是由于Max Nanasy上面的观察。