views:

367

answers:

2

I am trying to add a post-commit hook to a bare repository, such that whenever a commit is made the changed files are automatically installed in a (hardcoded) directory.

Is there a way to fetch a single file from the repository?

git-clone does not appear to allow for specifying a path, and any other commands that I found (git-fetch, git-pull) seem to require an existing local git repository to work.

Is there a way to do this?

+1  A: 

You may find the answers in: How to do a "git export"

In particular, git checkout-index will probably do the job for you:

git checkout-index -a -f --prefix=/destination/path/

Don't forget the trailing slash or this command won't do exactly what you want.

Greg Hewgill
git checkout-index does not work with a bare repository ("fatal: This operation must be run in a work tree").However, the link that you posted also suggests git-archive, which works fine: ("git archive master TESTFILE | tar -x -C /my/destination") Thanks!
knipknap
Ah, interesting, I guess a bare repository doesn't have an index to read from. Good to know.
Greg Hewgill
A: 

You can extract a single file from any revision in a bare repository with git show, using the syntax git show <rev>:<filename>, e.g.:

 $ ls
 branches  config  description  HEAD  hooks  info  objects  packed-refs  refs
 $ git show master:COPYING > /tmp/COPYING
 $ head -5 /tmp/COPYING
                     GNU GENERAL PUBLIC LICENSE
                        Version 3, 29 June 2007

  Copyright (C) 2007 Free Software Foundation, Inc. 
  Everyone is permitted to copy and distribute verbatim copies

There are a couple of examples in the git-show(1) man page. I hope that's of some use.

Mark Longair