是否有可能看到谁在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 2.23开始,你可以使用Git blame——ignore-rev
对于问题中给出的例子,这将是:
git blame -L10,+1 src/options.cpp --ignore-rev fe25b6d
(然而,这是一个棘手的问题,因为fe25b6d是该文件的第一个修订!)
其他回答
您可以使用git log -L来查看一行范围的演变。
例如:
git log -L 15,23:filename.txt
表示“跟踪文件名.txt文件中第15行到第23行的演变”。
还有递归指责。它可以安装
npm install -g recursive-blame
从Git 2.23开始,你可以使用Git blame——ignore-rev
对于问题中给出的例子,这将是:
git blame -L10,+1 src/options.cpp --ignore-rev fe25b6d
(然而,这是一个棘手的问题,因为fe25b6d是该文件的第一个修订!)
基于stangls的答案,我把这个脚本放在我的PATH(甚至在Windows上)作为git-bh:
这允许我查找所有涉及到一个词的提交:
git bh path/to/myfile myWord
脚本:
#!/bin/bash
f=$1
shift
csha=""
{ git log --pretty=format:%H -- "$f"; echo; } | {
while read hash; do
res=$(git blame -L"/$1/",+1 $hash -- "$f" 2>/dev/null | sed 's/^/ /')
sha=${res%% (*}
if [[ "${res}" != "" && "${csha}" != "${sha}" ]]; then
echo "--- ${hash}"
echo "${res}"
csha="${sha}"
fi
done
}
如果你正在使用JetBrains Idea IDE(和衍生品),你可以选择几行,右键单击上下文菜单,然后Git ->显示历史选择。你将看到影响选定行的提交列表: