How to Export a Single File Form a Git Revision to the Local Working Copy

I needed to test an older version of a file in a web app, but didn't want to checkout the entire codebase. The method below allowed me to easily checkout an older version of the file using the commit hash that I knew had the correct file. Other git object references such as tags, branches, and commits from HEAD can be used instead of the commit hash (full or short SHA). See details here.

$ git show [commit-hash]:/path/to/file/file.txt > file.txt

Blog Category: