7

I would like to update a specific file in a repository that I use.

Basically I have repo X, which has N files.

For one test, I need to have the latest and greatest of a specific file, since my application is already loaded, I can't just download the whole project again.

Is there a way to tell git to get from the repo, the latest and greatest version of just a specific file, without sync the whole repo/project?

I see that many uses the archive option of git, which to me seems a bit an overkill...I need to send a command to archive, and then another to unarchive on my local directory; while I would like that git would simply look at the repo, and if there are changes only to that specific file, it will update it.

How do you do that? I can't see in Git manual a way to specify a file in the repo. I use regular git from console, no UI nor Github.

  • This is a duplicate or near duplicate of http://stackoverflow.com/questions/16230838/git-is-it-possible-to-pull-just-for-one-file – David Hoelzer Jan 12 '15 at 23:23
  • It looks similar, but in my question I simply need to checkout the file from the repository. –  Jan 13 '15 at 00:04

1 Answers1

17

First make sure you have the latest and greatest version available in your local git repo:

git fetch origin

Then retrieve the one specific file you're looking for

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

The -- tells git that all other arguments are files, not parameters.

Arjan
  • 9,784
  • 1
  • 31
  • 41
  • Thanks Arjan; I fetch often so I just need the git command for the checkout –  Jan 13 '15 at 00:03