Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
445 views
in Technique[技术] by (71.8m points)

Using git to identify all modified functions in a revision

Is there a good way to use git to identify all the modified functions in each revision in the history? I've tried using the -p switch, but it doesn't seem to work in the same way that svn's show-c-function parameter works.

My assumption is that I'll want to use "git diff HEAD~i HEAD~i-1 -p" for increasing values of i. Am I missing some parameters that will help identify diff's best guess on the functions that were modified?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Here is a magic chant to list functions within a git diff *

git diff |                  
grep -E '^(@@)' |           
grep "(" |                  
sed 's/@@.*@@//' |          
sed 's/(.*//' |             
awk -F " " '{print $NF}' |  
uniq

...and what it does is...

  1. Picks the current diff,
  2. next picks only lines with "hunk-headers" ,
  3. next picks only lines with opening parenthesis (as potentially containing function names),
  4. next ignores the hunk headers,
  5. next ignores the text after the opening parenthesis,
  6. next picks only the word immediately before the opening parenthesis,
  7. and lastly ignores multiple occurrences of the same word in the list.

Voila! you have a list of functions being modified by the current git diff.


* Verified using git version 2.7.4 on Ubuntu 16.04 running bash.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.7k users

...