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
However, I'd like to know if is there a similar way in git to extract a tree (directory) and everything under it recursively?
I've written a small script that does this, so I'll add that as a possible answer. It seems that this is the kind of thing that may well be built in to git, but I just don't know how to find it...
Git cannot clone a tree directly. You need to clone the entire repository, and then check out a commit that uses the tree you want.
A Git tree object creates the hierarchy between files in a Git repository. You can use the Git tree object to create the relationship between directories and the files they contain. These endpoints allow you to read and write tree objects to your Git database on GitHub.
You can use git archive
for this.
git archive master:src/ | tar -C destination -x
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With