简体   繁体   中英

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 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 blame -M -C -C -C -w

from 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.

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

will help you print all of related commits.

Br, Tim

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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