git 函数重载的历史

git history of a function with overloading

用git显示函数历史,我可以用git -L :functionName:fileName

但是对于某些语言,例如 C++,函数重载允许多个具有相同函数名称的函数,例如,

int sum(int a,int b)
{
    return a+b;
}

double sum(double a,double b)
{
    return a+b;
}
float sum(float a,float b)
{
    return a+b;
}

如何显示一个特定的函数历史记录?

来自git doc

-L ,: -L ::
....

If “:<funcname>” is given in place of and , it is a regular expression that denotes the range from the first funcname line that matches <funcname>, up to the next funcname line. “:<funcname>” searches from the end of the previous -L range, if any, otherwise from the start of file. “^:<funcname>” searches from the start of file.

:function 是一个正则表达式,它将函数与模式 function 匹配并跟踪它的历史。

所以要跟踪具体功能,只需修改模式使其更清晰即可。

例如要跟踪 double sum(double a,double b) 只需使用 git log -L :sum\(double:filepath