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”
You mean
git tag
.git grep
takes any number of treeishs, not just one.So that makes it:
You might also want to try this:
(Your comment textarea could really stand to be bigger.)
No, I mean
git branch -a
becausegit 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.
For the record (although it might not be much help if you need to go two-way with
git svn
), Converting git-svn tag branches to real tags.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. 😦