如何使用 git 查找文件中特定行的差异历史记录?

How to find the diff history of specific line in a file using git?

例如,我想查找文件中特定行的历史记录列表

file: something.txt

1/2
line 1: // change comment to 1

2/15
line 1: // change comment to 2

12/15
line 1: // change comment to 4

如果我做 git blame 它只显示 12/15 条目,如果 2/1512/15 之间有大量提交,那么 git log 不是很有用

有人可以给我一些建议吗?

谢谢

以你的例子为例:

git log -L 1,1:something.txt

来自documentaion

-L <start>,<end>:<file>

-L :<funcname>:<file>

Trace the evolution of the line range given by "<start>,<end>" (or the function name regex <funcname>) within the <file>. You may not give any pathspec limiters. This is currently limited to a walk starting from a single revision, i.e., you may only give zero or one positive revision arguments. You can specify this option more than once.