Search Git history

Version control systems like Subversion, Mercurial, and Git are extremely useful in science. These systems were originally designed to manage software development projects where keeping a detailed history of all edits to the source code is extremely important. However, there are limitless uses to version control systems in science–I’ve used them for data management, manuscript preparation and collaboration, and software projects, both big and small. I use Git for most of my version control needs.

Perhaps an example will demonstrate how useful it can be to use version control for, let’s say, manuscript preparation. Earlier this week I was working on my manuscript and trying to find a reference for a paper. After searching for a bit, I realized I must have deleted the reference from my document. Rather than going out to the internet, trying to find the paper again, and exporting the citation, I decided I would search through older revisions of my document to find the citation.

I remembered the reference was for a paper that discussed the F1 score. So I used entered the following commands into my Terminal.

for revision in `git rev-list --all`
  git grep -F 'F1' $revision

The output of this command made it very easy to determine the ID of the last revision of my document that had the reference. I was then able to checkout that revision and find the reference I needed.

git checkout 98f327b894657f48899acc76e1dc3026584d29e4

Thanks to StackOverflow for today’s lesson!


Leave a Reply

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

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s