patterngitModerate
Getting a single revision from Git
Viewed 0 times
revisiongettingsinglegitfrom
Problem
Having the full Git revision history has a lot of benefits as part of the development process.
But our product is the source code, we are using scripted languages that don't need compilation or processing, and then the Git history becomes a burden on deployment- in our example we deploy a clean virtual environment following every change, having several deployments on a single machine.
There are some ways to reduce the amount of history, for example shallow clones whose efficiency depends on how deep the revision is in the branch, doing a fetch instead of clone but then you still get history from the revision and back, or getting the full repo once then pull when needed but this is wasteful in terms of disk space and tends to be less reliable.
Is there a way to get a single revision from Git without it's history ?
But our product is the source code, we are using scripted languages that don't need compilation or processing, and then the Git history becomes a burden on deployment- in our example we deploy a clean virtual environment following every change, having several deployments on a single machine.
There are some ways to reduce the amount of history, for example shallow clones whose efficiency depends on how deep the revision is in the branch, doing a fetch instead of clone but then you still get history from the revision and back, or getting the full repo once then pull when needed but this is wasteful in terms of disk space and tends to be less reliable.
Is there a way to get a single revision from Git without it's history ?
Solution
Shallow clone
You can indeed get a shallow clone out of Git using:
This will still clone the repo and create a
Git archive
You can also use git-archive to extract an archive of the repo:
Creates an archive of the specified format containing the tree structure for the named tree, and writes it out to the standard output. If is specified it is prepended to the filenames in the archive.
In the examples it shows for instance:
Create a compressed tarball for v1.4.0 release.
Hosted Git, archive API
If you are hosting your repo on GitHub, then you can use their archive API:
Bitbucket.org has a same functionality for this:
You can indeed get a shallow clone out of Git using:
git clone --depth=1 This will still clone the repo and create a
.git folder with the objects, only smaller in size (difference depending on your total file size vs. history size).Git archive
You can also use git-archive to extract an archive of the repo:
Creates an archive of the specified format containing the tree structure for the named tree, and writes it out to the standard output. If is specified it is prepended to the filenames in the archive.
In the examples it shows for instance:
git archive --format=tar --prefix=git-1.4.0/ v1.4.0 | gzip >git-1.4.0.tar.gz Create a compressed tarball for v1.4.0 release.
Hosted Git, archive API
If you are hosting your repo on GitHub, then you can use their archive API:
https://api.github.com/repos///zipball/Bitbucket.org has a same functionality for this:
https://bitbucket.org///get/.zipCode Snippets
git clone --depth=1 <url>Context
StackExchange DevOps Q#406, answer score: 16
Revisions (0)
No revisions yet.