91

I have an Amazon EC2 machine. I would like to clone an older version of github repo on this machine. Normally I use git clone https://linktomyrepo.git How can I clone an older version, say an update from 14 days ago? I can see the exact version I need in the commit history of repository, but do not know how to clone it onto the EC2 machine. Do I need to use the little SHA code next to each commit?

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Mobie
  • 1,850
  • 4
  • 19
  • 25

5 Answers5

89

You can always check out any given state by using a commit hash.

For instance, by looking at the log, you identified that 233ab4ef was the state you were interested in: issue a git checkout 233ab4ef to check out that state.

Another way to achieve this is by using git checkout @{14.days.ago}

Olivier Refalo
  • 50,287
  • 22
  • 91
  • 122
  • 2
    what's `14` in `git checkout @{14.days.ago}` exactly ? – Shafizadeh Dec 31 '16 at 18:07
  • 4
    It looks like the number of days ago that you're looking to clone. Apologies if that's not what you were asking. This says "Clone the repo based on what it looked like 14 days ago from today" if I read this right. – jrb Nov 03 '17 at 21:35
  • And about "contibue my project from this older version"? Can I do changes and "restart commits" from it? – Peter Krauss Nov 08 '19 at 13:06
52

Git is not designed that way. When you clone a repository, you are copying all versions.

So first clone a repository (which does initially checkout the latest version), then checkout the version you actually want.

You can checkout the commit based on the hash.

git checkout afe52

You can also checkout based on date (instead of looking up the hash), eg:

git checkout 'master@{1979-02-26 18:30:00}'
git checkout @{14.days.ago}

To check the commits you can checkout, use git log.

ronalchn
  • 12,225
  • 10
  • 51
  • 61
  • 1
    What if there are thousands of commits? What's the fastest way to see all the tagged releases? Say for things like version 1, 2, 3, etc. – fIwJlxSzApHEZIl Mar 02 '16 at 19:26
  • 1
    @anon58192932 to view all the tags you can use `git tag` and to view the details of that specific tag, you can use `git cat-file tag TAG_NAME` for example I could use `git cat-file tag v4.4.7` in the node repo to give me show me the commit string `0974fc6a25c343744235331eb20d31f6412ff7e1`. :) – Dobz Jul 27 '16 at 10:49
18

Also for Github.com UI,

For those wanting to download a specific Commit, steps are below:

  1. Go to "Commits"
  2. Click the "<>" icon to the right of the desired commit
  3. Select Clone or Download
  4. Download ZIP

Commits

Select Commit

Download ZIP

TSpartanT
  • 189
  • 1
  • 3
  • This is helpful! I don't know how I missed this, but spent a solid 15mins trying to figure out how to download an older state copy of the repo as a standalone zip. Perfect, thank you! – Benbodhi Jul 26 '21 at 07:47
1

Old version on Github usually means an old branch. For example:

enter image description here

In this case you can check out the old branch by using its branch name:

git clone --branch <branchname> <remote-repo-url>

The remote-repo-url you can get here:

enter image description here

ESP32
  • 8,089
  • 2
  • 40
  • 61
0

Posting this solution specifically for github.com UI.

I was using an older version of Keycloak and wanted to download the source. On github.com, it was a simple process:

  1. Go to releases section
  2. Download the required release.

enter image description here enter image description here

tryingToLearn
  • 10,691
  • 12
  • 80
  • 114