Checking out a file from a specific commit in Git

To check a single file from a specific Git commit, just specify the commit and file path in git checkout command.

Command syntax

$ git checkout <commit> -- <file-path>

Examples

# Checkout asset/css/style.css from commit 8bc723c
$ git show 8bc723c asset/css/style.css

# Checkout asset/css/style.css from the parent commit.
$ git show HEAD~ asset/css/style.css