2

I am trying to get the names of the functions that contains changes via "git diff " command. Is there a simple way to do it?

I want to make a report that shows which functions were changed. I tried "--name-only" flag, but it only gives changed files, and I need changed functions.

Output: show_time($$) show_date($$)

  • You can filter the output from the git diff with some shell commands. Git itself doesn't recognise functions, each language has different syntax, git is not "trained" on a language, but there might be packages that can enhance such functionality for git. – Petronella Sep 02 '19 at 09:54
  • 1
    Git does not care enough for the inner structure of the source code to get this information out in a direct way. The underlying diff command puts function names sometimes into the hunk line indicators (lines starting with @@), but it fails to find every reference, and also happily continue with the diff even if other function names are found along the way. – Rudi Sep 02 '19 at 10:57

1 Answers1

1

As seen in "Where does the excerpt in the git diff hunk header come from?", a diff hunk can include the name of the function.

You could grep this hunk header in order to get the list of functions, provided the file is in one of the supported languages.
(Or you would need to customize the diff)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250