Extracting a blob (file) from an arbitrary revision is easy with git show
, e.g.:
git show master:src/hello-world.c > /tmp/hello.c
You can use read-tree
and checkout-index
with a temporary index file:
GIT_INDEX_FILE=.tmp.index { git read-tree master:src &&
git checkout-index -a --prefix=dest/;
rm -f .tmp.index; }
(Line breaks added for clarity, but it's really a one-liner.)
For a bare repository you have to pretend that a working tree exists and that you are in it:
GIT_INDEX_FILE=.tmp.index GIT_DIR=/path/to/repo.git GIT_WORK_TREE=. {
git read-tree master:src &&
git checkout-index -a --prefix=/path/to/dest/;
rm -f .tmp.index; }
If run from inside the bare repository you can omit setting GIT_DIR
.