Retrieving a single file from a specific revision in Git

git show :path/to/file > path/to/file

I was doing some debugging today and at one point was trying to find which file in a particular commit had caused a problem. First, of course, I checked out the commit right before this one to double check that the problem code was actually in that commit:

git checkout <COMMIT>~1

However, then I wanted to merge the changes from that commit into the repository one by one so I could narrow the problem down to a single file. I didn’t want to type everything out again by hand, so I used the following command to execute file changes one-by-one:

git show <COMMIT>:path/to/file/from/repo/root > path/to/file

It’s just a simple combination of the ‘git show’ command to see the file in a current commit and a Bash ‘>’ to pipe that content into the actual file and overwrite its content on disk.

Written by Mpdaugherty on Friday, 10th June 2011. Leave a comment.
Posted in: Git

Earlier entries

  1. Aquamacs - Where to set preferences Friday, 3rd June 2011
  2. Using git through a proxy Wednesday, 20th April 2011
  3. Upgrading to Django 1.3 Friday, 15th April 2011
  4. Big decisions - the Engineering approach Thursday, 7th April 2011
  5. Announcing Django-Vehicles Thursday, 31st March 2011
  1. 2011