git: checkout a specific revision of a file

Sometimes, you need to patch a specific file but you can’t pull the whole branch when deploying.

To checkout a specific version revision of a file,  git syntax is :

git checkout -m 4a3171c -- filename

For example, to get the last revision number of your master branch, look at your git fetch ouput :

$ git fetch
remote: Counting objects: 7, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 4 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (4/4), done.
From host:repository
 5cdc9ae..4a3171c master -> origin/master

Here, your latest revision on master is 4a3171c

To update a specific file at that revision, you’ll invoke git like this :

git checkout -m 4a3171c -- myfile