aaron maxwell

Git: Checkout or Export Specific Revision of Repository

Here's how to checkout, or export, the contents of a whole Git repository at a specific commit. (Note for Subversion expats: It's the equivalent of "svn co -r REV" or "svn export -r REV".)

To get a checkout of the sources at commit/revision TREEISH:

git clone src working
cd working
git reset --hard TREEISH

Here, "src" is the path or URL of the git repository, and "working" is the new directory you want created to hold the files.

If you want to do an export instead, it's usually fine to just remove the .git directory from "working". Alternatively, you can add one step to the above:

git-checkout-index -a --prefix=export/

Here, "export" is the directory you want the exported files placed. (Remember that trailing slash, it's important!) You can remove "working" afterwards; if your final goal is the export, "working" is just an intermediate set of files.

(It's possible to use git reset --mixed to move the index of the original repository, "export" from that, then move the original repository's HEAD back to its previous tip. I propose the clone-based method instead, since it leaves less room for anything to go wrong.)