Skip to content

How to download a specific commit from a Git repository #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
rogerxu opened this issue Oct 28, 2016 · 3 comments
Open

How to download a specific commit from a Git repository #21

rogerxu opened this issue Oct 28, 2016 · 3 comments
Labels

Comments

@rogerxu
Copy link
Owner

rogerxu commented Oct 28, 2016

Sometimes we need to download a specific version of a project from a Git repository to do some work like build from source code. If clone the entire repository it will be very slow because we don't need the entire commit history.

GitHub provides a download as zip service for a specific version which meets our needs. But how about a Git repository accessed via SSH?

@rogerxu
Copy link
Owner Author

rogerxu commented Oct 28, 2016

How do I download a specific git commit from a repository? - Stack Overflow

Do a "git export" (like "svn export")? - Stack Overflow

Excluding files from git archive exports using gitattributes

Git - git-archive Documentation

git archive [--format=<fmt>] [--list] [--prefix=<prefix>/] [<extra>]
          [-o <file> | --output=<file>] [--worktree-attributes]
          [--remote=<repo> [--exec=<git-upload-archive>]] <tree-ish>
          [<path>…​]

Example:

git archive -v --format=zip --output=archive.zip [email protected]:rogerxu/webpack-demo.git master app/images

@rogerxu
Copy link
Owner Author

rogerxu commented Oct 28, 2016

GitHub

git - How to download .zip from GitHub for a particular commit sha? - Stack Overflow

Download URL

You can put the sha that you want in the download url:

https://github.com/{username}/{projectname}/archive/{sha}.zip

As a general rule, if you have a url that works, you can replace "master" with the specific sha you want.

git archive --remote

As far as I know Github does not allow archive --remote for HTTPS protocol. git archive works fine with GitHub, as long as you use the ssh protocol.

git archive -v --format=zip --output=archive.zip [email protected]:rogerxu/webpack-demo.git master app/images

svn export

How to download a project subdirectory from GitHub (Example)

svn export https://github.com/rogerxu/webpack-demo/trunk/app/images archive

@rogerxu
Copy link
Owner Author

rogerxu commented Oct 28, 2016

Ref Mapping

  • 1.1.0-SNAPSHOT => branch rel-1.1
  • 2.0.0 => tag 2.0.0
  • 2.0.1-SNAPSHOT => branch rel-2.0
  • 2.1.0-SNAPSHOT => branch develop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant