Rafid Rafid - 4 months ago 27
Git Question

GIT: Checkout to a specific folder

I want to use something similar to:

git checkout -- <path>/<file>

but I want to checkout the file to some folder I choose, rather than the overwriting the local /.

Any idea?


As per How to do a "git export" (like "svn export")

You can use git checkout-index for that, this is a low level command, if you want to export everything, you can use -a,

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

To quote the man pages:

The final "/" [on the prefix] is important. The exported name is literally just prefixed with the specified string.

If you want to export a certain directory, there are some tricks involved. The command only takes files, not directories. To apply it to directories, use the 'find' command and pipe the output to git.

find dirname -print0 | git checkout-index --prefix=/path-to/dest/ -f -z --stdin

Also from the man pages:

Intuitiveness is not the goal here. Repeatability is.