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

后端 未结 7 1486
我寻月下人不归
我寻月下人不归 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:19

    The closest thing you can do is to determine the position of your function in the file (e.g. say your function i_am_buggy is at lines 241-263 of foo/bar.c), then run something to the effect of:

    git log -p -L 200,300:foo/bar.c
    

    This will open less (or an equivalent pager). Now you can type in /i_am_buggy (or your pager equivalent) and start stepping through the changes.

    This might even work, depending on your code style:

    git log -p -L /int i_am_buggy\(/,+30:foo/bar.c
    

    This limits the search from the first hit of that regex (ideally your function declaration) to thirty lines after that. The end argument can also be a regexp, although detecting that with regexp's is an iffier proposition.

提交回复
热议问题