Categories
Uncategorized

Searching through all revisions

A colleague was asking:

I’m trying to work out a technique for searching for an occurrence of a phrase in _all_ revisions of a specific file in a subversion repository. How can I do this?

Of course, in subversion, the answer is slow and complicated. But, you can use git (and git svn in particular) to achieve the answer fairly simply (and much more quickly).

First, you just clone the subversion repository into git. This takes a while, mostly because subversion isn’t that quick.

  git clone -s https://svn.example.com/proj

Then, you can wrap a little bit of shell scripting around git to get what you need.

  cd proj
  git branch -a | grep tags/ | while read tag
  do
    git --no-pager grep 'something' $tag -- some/file.txt
  done

So, we pull out a list of tags, and run git grep over each one.

There may well be a more effective way to do this, but hey, it took seconds to come up with. And it shows off the reason I like git — it’s so scriptable.

4 replies on “Searching through all revisions”

git branch -a | grep tags/

You mean git tag.

while read tag ; do git grep foo $tag ; done

git grep takes any number of treeishs, not just one.

So that makes it:

git grep 'something' `git tag` -- some/file.txt

You might also want to try this:

git log -S 'something' --tags

(Your comment textarea could really stand to be bigger.)

No, I mean git branch -a because git svn clone turns svn tags into git branches. Which is yucky, but hasn’t bothered me too much so far.

I did play (briefly) with the treeish notation, but couldn’t quite get it to work, so I went for the simpler solution.

Thanks for that — I did need to do that when I converted my personal repo’s to git. I think I hacked up something similar by hand… Sadly the work stuff is in svn and likely to stay that way for a while. 😦

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s