简体   繁体   中英

How do I download source code of all the versions of a repository on Github using some automated script?

I have details of few public repositories on GitHub. Is there a way to write a script which downloads the source code of all those repositories on to my local machine? While downloading the source code I want all the previous versions of project to be downloaded.

Ex: Project RxJava has about 124 releases as shown here . I want to know if there is a way to write a program which downloads source code of all these 124 releases on to my machine. I don't want to click on download source code button on each of these releases.

The easiest is to:

  • clone the repo (that will give you the sources matching each tags)
  • do a git tag and for each tag, curl the release.
    Actually, since the release is the source code, you don't have to curl anything.

To access the source code of a "release", simply checkout the tag matching the release.

cd /path/to/cloned/repo
git checkout 1.0.8

This is how I figured the solution:

  1. Using the Repository Search API get the details of required the projects.
  2. This gives you a JSON object which has the below property

    "releases_url": " https://api.github.com/repos/ReactiveX/RxJava/releases ",

  3. Use the above url to get a JSON object which describes release details of project

  4. The JSON obtained in step 3 has a property as given below for each version of project

    "zipball_url": " https://api.github.com/repos/ReactiveX/RxJava/zipball/v1.0.8 ",

  5. Now copy the content from above URL in to an output stream to fetch the required source code.

  6. Sample source code is available here

I know I am seven years late, yet I think this solution might help people with the same prolem:

I developed a simple bash script that you can find inthis GitHub Gist that allows you to download all versions from every file currently in the repository. The output data is located in subfolders matching the name of the file, containing all its versions. The original directory tree of the repository is kept.

Hope anyone finds this useful!

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