Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to copy a SINGLE FILE from LOCAL REPOSITORY to my machine, not git-pull or git-fetch, how can i do it?

Is it possible to get it via hash ? such as a3ea2118bf1c5e2c6aa0974d0b6ff7415bd044ef ?

share|improve this question
If the repository is local, just cp unless it's a bare repo. – jordanm Oct 24 '13 at 4:39
Fetch and clone work just the same locally and over the network, so answers should be the same as for: stackoverflow.com/questions/2466735/… – Ciro Santilli 巴拿馬文件 六四事件 法轮功 Mar 30 at 10:52
up vote 8 down vote accepted

You can use git archive to obtain a single file from a repository:

git archive --remote=file:///path/to/repository.git HEAD:path/to/directory filename | tar -x

The repository specified as --remote can be local, remote, bare or regular, it works in all of the aforementioned cases.

Note that if you want to obtain a version of filename from a specific commit, you can replace HEAD in the oneliner above with the hash of the desired commit.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.