8

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 ?

2
  • 3
    If the repository is local, just cp unless it's a bare repo. Commented Oct 24, 2013 at 4:39
  • 1
    Fetch and clone work just the same locally and over the network, so answers should be the same as for: stackoverflow.com/questions/2466735/… Commented Mar 30, 2016 at 10:52

1 Answer 1

12

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.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.