Git - how do I view the change history of a method/function?

后端 未结 7 1462
我寻月下人不归
我寻月下人不归 2020-11-28 19:55

So I found the question about how to view the change history of a file, but the change history of this particular file is huge and I\'m really only interested in the changes

7条回答
  •  离开以前
    2020-11-28 20:33

    Recent versions of git log learned a special form of the -L parameter:

    -L ::

    Trace the evolution of the line range given by "," (or the function name regex ) within the . 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.
    ...
    If “: is given in place of and , it is a regular expression that denotes the range from the first funcname line that matches , up to the next funcname line. “: searches from the end of the previous -L range, if any, otherwise from the start of file. “^: searches from the start of file.

    In other words: if you ask Git to git log -L :myfunction:path/to/myfile.c, it will now happily print the change history of that function.

提交回复
热议问题