Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best way to extract a tree from a git repository?

Tags:

git

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...

like image 369
Mark Longair Avatar asked Jul 29 '10 16:07

Mark Longair


People also ask

How do I clone a Git repository tree?

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.

What is a Git tree?

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.


1 Answers

You can use git archive for this.

git archive master:src/ | tar -C destination -x
like image 147
CB Bailey Avatar answered Nov 11 '22 01:11

CB Bailey