Cloning an older version of github repo

GitGithubGit Checkout

Git Problem Overview


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?

Git Solutions


Solution 1 - Git

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}

Solution 2 - Git

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.

Solution 3 - Git

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

Solution 4 - Git

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

Solution 5 - Git

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 you can get here:

enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMobieView Question on Stackoverflow
Solution 1 - GitOlivier RefaloView Answer on Stackoverflow
Solution 2 - GitronalchnView Answer on Stackoverflow
Solution 3 - GitTSpartanTView Answer on Stackoverflow
Solution 4 - GittryingToLearnView Answer on Stackoverflow
Solution 5 - GitGerfriedView Answer on Stackoverflow