git - 如何找出一行代码的变更历史

标签 git

git blame 可用于找出修改了哪个提交,但我遇到了一种情况,整个文件似乎是从某个我无法分辨的地方复制的。

$ git blame a.c
c59f772b (a@google.com 2011-08-25 01:07:44 +0000   1)   #include <stdio.h>
c59f772b (a@google.com 2011-08-25 01:07:44 +0000   2)   
c59f772b (a@google.com 2011-08-25 01:07:44 +0000   3)   int main(int argc, char **argv) {
c59f772b (a@google.com 2011-08-25 01:07:44 +0000   4)       void *handle;
c59f772b (a@google.com 2011-08-25 01:07:44 +0000   5)       double (*cosine)(double);
...

$ git log c59f772b
commit c59f772bc273e65985236ba665f7a88492a33235
Author: a@google.com
Date:   Thu Aug 25 01:07:44 2011 +0000

    Cloning a bunch of stuff from the another repository
    No changes, as is.

这次提交只是复制代码。我仍然不知道这段代码到底是谁写的。

我能有一份代码变更历史或类似内容的列表吗?

最佳答案

看一眼 git 的力量 :)

git blame -M -C -C -C -w

来自git help blame:

-C

In addition to -M, detect lines moved or copied from other files that were modified in the same commit. This is useful when you reorganize your program and move code around across files. When this option is given twice, the command additionally looks for copies from other files in the commit that creates the file. When this option is given three times, the command additionally looks for copies from other files in any commit.

关于git - 如何找出一行代码的变更历史,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15104112/

相关文章:

git - 如何解决git错误: Server does not allow request for unadvertised object 3a2ceef391af73994dfeb0d8ef57ed6a52ef4238?

linux - 为什么来自 github 存储库的 https 上的 "git pull"命令需要 "sudo"作为前缀?

swift - 从 Storyboard 创建 Swift 代码

git - 包含敏感数据的私有(private)和公共(public) Git 存储库

git - 您可以使用 libgit2 克隆 git 存储库吗?

git - 通过 HTTP 推送到本地托管的 git 存储库

git - 我如何发现差异由哪些提交组成?

Git Bash 仅在禁用 Trend Micro 时工作

Git:如何从主分支中较早/较旧的提交创建新分支?

javascript - GitGraph - 缩放图表的大小