简体   繁体   English

我如何找出一行代码的更改历史记录

[英]How do I find out change history of a line of code

git blame can be used to find out which commit modified, but I ran into a situation that it appears the whole file is copied from somewhere that I can't tell. 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.

This commit is just about copying the code. 该提交仅与复制代码有关。 I still don't know which and who actually wrote this code. 我仍然不知道哪个人真正写了这段代码。

Can I have a list for change history of code or something similar? 我可以列出代码的更改历史记录或类似内容吗?

Glance at the power that is git :) 瞥见git的力量:)

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

from git help blame : git help blame

-C

In addition to -M, detect lines moved or copied from other files that were modified in the same commit. 除了-M之外,还检测在同一提交中从其他文件移动或复制的行。 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. 给出该选项3次后,该命令还会在任何提交中从其他文件中查找副本。

It seems there is no good way because you just copy the file from another palce and commit it. 似乎没有好办法,因为您只是从另一个地方复制文件并提交。

If you know those class, you can use git commit --author authorname 如果您知道这些类,则可以使用git commit --author authorname

will help you print all of related commits. 将帮助您打印所有相关的提交。

Br, Tim Br,蒂姆

If you want to show the changes to a single file, and see the file name changes do the following: 如果要显示对单个文件的更改,并查看文件名更改,请执行以下操作:

git log --stat --follow -- <filename>

Now to blame the file from that previous point you'll have to specify the old file name that may not exist anymore. 现在,要责怪该文件,您必须指定可能不再存在的旧文件名。

git blame <hash_before_move> -- <old_file_name>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM