Sometimes it would be nice to be able to say something like:

(git|svn|hg|etc) diff Foo.c:main
(git|svn|hg|etc) log log Foo.c:main

to see the changes made to a specific function within a source file since the last commit, or the complete history of changes. My question is two-fold:

  1. Does something exist that does this?
  2. Would such a tool be practical? It would have to do some simple parsing of the code at each revision in order to compare different versions of the function; would the overhead be too much for it to be efficient?
  • 7
    The need for this seems like it would be a symptom of an underlying problem, like methods being too large or classes not being properly organized, as any VCS worth its salt will give you a diff of the class, and it's easy enough to scroll down to (or search for) the method in question if the class isn't too large, and you get to see the code in the method within the context of the whole class. In short, I think method resolution is too specific. Nov 18, 2011 at 23:48
  • @Robert that is a good point, and I think my motivation for wondering is partly due to at least a little code bloat. I traced a bug to a specific method and want to be able to see a log of changes to just that method to see where it broke, and full diffs can be slightly inconvenient to search through if you're in a hurry :)
    – jches
    Nov 19, 2011 at 0:23
  • 4
    For the very rare case when this is useful, TortoiseXXX's Blame feature is pretty powerful. You can see when the last changes were made to all lines in the method and, using the right margin, keep stepping back through those changes.
    – pdr
    Nov 19, 2011 at 0:31

6 Answers 6

  1. As far as I know, it does not. One might, but I would not expect it to be production quality if it did.
  2. I don't think it is practical, but not for the reason you listed. It is not practical because the VCS would have to be language aware to support that kind of functionality. Essentially, you would need to embed something to parse the language text (one of the big steps a compiler does). This adds a lot of extra weigh to you VCS, which is already doing a fairly complex job.
    But more importantly, you would need to do the same thing for every language you want to support. A VCS who's selling point only works on C code is not going to get a lot of traction. Even if you ignore all the obscure languages, it would be a massive undertaking to support even the top 10 languages.

And as Robert pointed out, being able to immediately jump to a method is not a huge gain over having to manually jump to the method within the diff tool.

  • 4
    I second the point of language dependency and having a lot of redundant code Nov 19, 2011 at 0:11
  • 1
    The same argument could be made against code highlighting editors though; they must be language-aware, and do indeed exist. Maybe the payoff is a little higher though (colorful screens of codez!). I agree parsing would probably be the hardest part. It wouldn't be that hard to support the most common languages though, especially since you don't need to fully parse the program.
    – jches
    Nov 19, 2011 at 0:30

svn actually does something close to what you want.

You can use the command :

svn diff -x -p program.c 

The -x -p provides 'C' function name on top of the change set. which looks like this.

@@ -97,6 +102,8 @@ int function1(int *x)

It doesn't filter but you can grep/search to serve your purpose closely.

I guess this is only for 'C' (or C/C++). However, i guess, if there is a demand svn would make it available for other languages as well.

I don't quite subscribe to the argument that VCS should NOT do that. After all we want all IDEs or editors (like VIM,EMACS) to do syntax highlighting which is specific to each language and support many simultaneously. So VCS being a developer tool, should also support such functionality.

Of course, thanks to your question that i discovered it. I had never used it before.


Without going into specifics, ... but you might check out Semantic Designs site and their products range. They offer some tools which are language sensitive, so to say, in lack of a better term.


Monticello can do this (e.g. http://wiresong.ca/monticello/v2/docs/changes-browser.html) but this is of course cheating outrageously because it only works for Smalltalk.


To show what revision and author last modified each line of a file:

git blame filename
  • 1
    True, but the Q asks for a way to search for changes to a particular method within a file. Imagine that there are 100 revisions to a given file, and out of those you need to find the ones that include changes to a particular function.
    – Caleb
    Nov 19, 2011 at 14:12
  • Version control does not know about syntax details, and also doesn't care the types of files.
    – Ghita
    Nov 19, 2011 at 20:13

ENVY and StORE both do that. It's interesting that, as with Monicello that Logan Capaldo mentioned above, these too are for Smalltalk.

Not the answer you're looking for? Browse other questions tagged or ask your own question.