Search code examples
gitgit-diff

Function context in git diff for fortran?


git diff tries to provide context on the function, which a change is associated with, displaying the function name in the @@ header line. Alternatively, the whole function can be shown with the -W, --function-context flag.

However, this doesn't seem to work for Fortran.

Is it possible to make git aware of Fortran with respect to this feature? Maybe a regular expression for recognizing relevant lines?


Solution

  • I found a solution, posted by K. Lindsay as background for their question show fortran function names in svn diff. They knew the trick for Git but wanted same for SVN. I've added backticks to format code, but wording is verbatim:

    I've learned that if I place *.f90 diff=fortran in ~/.config/git/attributes, then git diff shows fortran subroutine/function names in the hunk headers.

    kdb says this seems to work for them too, so it seems still to be the way to do it! :-)