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 have cloned a xorg git repository:

git clone git://anonscm.debian.org/pkg-xorg/driver/xserver-xorg-video-intel

and I need to extract all files as they looked after commit 45c09bfe58c37bbf7965af25bdd4fa5c37c0908f

I know how to extract one file of a specified version, i.e.

git show 45c09bfe58c37bbf7965af25bdd4fa5c37c0908f:src/intel_driver.h > intel_driver.h

but how can I extract the whole structure (all files) ?

share|improve this question
git checkout? git archive? – Mikel Apr 12 '14 at 13:07
up vote 3 down vote accepted

To check out a specific commit:

git checkout 45c09bfe58c37bbf7965af25bdd4fa5c37c0908f

This will report an error if it would need to overwrite files that are not committed. To unconditionally overwrite file, pass the -f option.

To extract a commit without affecting the working copy:

git archive 45c09bfe58c37bbf7965af25bdd4fa5c37c0908f | gzip >../45c09bfe58c37bbf7965af25bdd4fa5c37c0908f.tar.gz
git archive --prefix=45c09bfe58c37bbf7965af25bdd4fa5c37c0908f/ 45c09bfe58c37bbf7965af25bdd4fa5c37c0908f | tar xf - -C ..

git archive gives you a tar archive, which you can extract elsewhere or store to a file.

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.