Git: How to update/checkout a single file from remote origin master?


The scenario:

  1. I make some changes in a single file locally and run git add, git commit and git push
  2. The file is pushed to the remote origin master repository
  3. I have another local repository that is deployed via Capistrano with the "remote_cache" method from that remote repository
  4. Now I don't want to deploy the whole application but just update/checkout that single file.

Is this somehow possible with git? I wasn't able to find anything that would work nor was I able to figure it out. With SVN I just did svn up file and voila.


It is possible to do (in the deployed repository)

git fetch
git checkout origin/master -- path/to/file

The fetch will download all the recent changes, but it will not put it in your current checked out code (working area).

The checkout will update the working tree with the particular file from the downloaded changes (origin/master).

At least this works for me for those little small typo fixes, where it feels weird to create a branch etc just to change one word in a file.

How much of a git sha is *generally* considered necessary to uniquely identify a change in a given codebase?

How to revert initial git commit?