Chris B.
Chris B.

Reputation: 90201

How do I check out a specific commit from Github?

I'm trying to checkout https://github.com/Miserlou/Zappa/commit/54a6fa4542a4ae26d5a8155b63a50701ab69c1f8.

$ git clone https://github.com/Miserlou/Zappa.git
Cloning into 'Zappa'...
remote: Enumerating objects: 15029, done.
remote: Total 15029 (delta 0), reused 0 (delta 0), pack-reused 15029
Receiving objects: 100% (15029/15029), 4.71 MiB | 932.00 KiB/s, done.
Resolving deltas: 100% (11418/11418), done.
$ cd Zappa
$ git checkout 54a6fa4542a4ae26d5a8155b63a50701ab69c1f8
fatal: reference is not a tree: 54a6fa4542a4ae26d5a8155b63a50701ab69c1f8

What am I doing wrong?

Upvotes: 2

Views: 318

Answers (1)

torek
torek

Reputation: 488183

The problem here is that 54a6fa4542a4ae26d5a8155b63a50701ab69c1f8 is only half-in the repository at https://github.com/Miserlou/Zappa.

That is, if you clone https://github.com/Miserlou/Zappa, you get a valid repository with a bit under 3000 commits in it. 54a6fa4542a4ae26d5a8155b63a50701ab69c1f8 is not one of those commits.

In fact, 54a6fa4542a4ae26d5a8155b63a50701ab69c1f8 is a commit in another repository. You can see this in https://github.com/Miserlou/Zappa/pull/1762, which displays, among other things:

 Open   purificant wants to merge 1 commit into Miserlou:master from purificant:py37 

So this commit is more properly in a fork owned by purificant under branch name py37 (hover over some of the labels and you'll see a bit more detail in pop-ups).

However, once someone makes a pull request on GitHub, those commits are available via the target repository as well. It just takes a bit of trickery:

git fetch origin refs/pull/1762/head:refs/heads/pr1762

Now git show 54a6fa4542a4ae26d5a8155b63a50701ab69c1f8 and git checkout 54a6fa4542a4ae26d5a8155b63a50701ab69c1f8 work.

$ git checkout 54a6fa4542a4ae26d5a8155b63a50701ab69c1f8
Note: checking out '54a6fa4542a4ae26d5a8155b63a50701ab69c1f8'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at 54a6fa4 python3.7 support

(It's not clear to me how someone who is not me would figure this out. :-) )

(The raw name pr1762 I used here is not a good one, I've edited it to read refs/heads/pr1762 instead.)

Upvotes: 6

Related Questions