简体   繁体   中英

With Git, is it possible to download a revision without cloning the repo?

Basically, I'd like to download the working tree at a particular revision without cloning anything. In particular, I don't want any .git directory in the resulting download. Another way to think of what I'm asking for is the converse of a bare repo: a bare working tree.

The use case is pretty straightforward, when you simply want to use the code or data without any intention of modifying it or playing with history.

I know of git clone --depth 1 , but in my experience the cloned repo is still twice as big as the working tree alone.

git archive can do the job

try : git archive -vvv --remote=<REPO_URL> -o output.zip <REF>

Please note: REF should be only a named ref - branch, tag, etc. It does not allow you to pick certain commit.

update

Download and extract oneliner

$ git archive -vvv --remote=<REPO_URL> -o archive.tar <REF> && tar -xvvf archive.tar && rm archive.tar

update 2

Better oneliner

$ git archive -vvv --remote=<REPO_URL> <REF> | tar -xvf -

You may use --prefix flag of git archive to add prefix dir or you may refer to tar docs to extract contents into other directory.

For example

$ git archive -vvv --prefix=stack/ --remote=<REPO_URL> <REF> | tar -xvf - $ git archive -vvv --prefix=stack/ --remote=<REPO_URL> <REF> | tar -xvf - will extract contents of repo into stack directory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM