2

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?

Chris B.
  • 85,731
  • 25
  • 98
  • 139
  • it shouldn't be an issue, can you show the ``git status``? – HRK44 Feb 15 '19 at 16:01
  • What does `git show 54a6fa45` result in? – evolutionxbox Feb 15 '19 at 16:01
  • `fatal: ambiguous argument '54a6fa45': unknown revision or path not in the working tree.` – Chris B. Feb 15 '19 at 16:02
  • If you get this error that means you are referring to a git hash that does not exist anymore. Try `git log ` and look if you can see that commit hash – Rmahajan Feb 15 '19 at 16:03
  • I can't find that commit locally, but I can see it (as can everyone) if you go to https://github.com/Miserlou/Zappa/commit/54a6fa4542a4ae26d5a8155b63a50701ab69c1f8 – Chris B. Feb 15 '19 at 16:04
  • It's likely that commit was unreachable so it was removed from the repo, but for completeness github still has it? – evolutionxbox Feb 15 '19 at 16:05
  • Possible duplicate of [Unable to fetch commit from github](https://stackoverflow.com/questions/43093393/unable-to-fetch-commit-from-github) – jonrsharpe Feb 15 '19 at 16:06

1 Answers1

6

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.)

torek
  • 448,244
  • 59
  • 642
  • 775
  • Also this link : https://help.github.com/articles/commit-exists-on-github-but-not-in-my-local-clone/ – HRK44 Feb 15 '19 at 16:06
  • @HRK44: yes, though those are for commits that *were* in a repository but are now gone, whereas this is for a commit that's sort of halfway-there. It may eventually be all the way there, or not, depending on what the owner of the repository does. – torek Feb 15 '19 at 16:08
  • So the confusion is due to Github rewriting their URL as if the commit comes directly from the repo... – HRK44 Feb 15 '19 at 16:20
  • @HRK44: not exactly: *while the pull request is present*, the commit *is* in the repo, it's just under a reference that `git clone` does not clone. As soon as the pull request is closed, the reference is dropped. At that point, if the commit *isn't* reachable from some other reference, it will be garbage collected, but until then you can still get to it by URL. That's why I called it "half in": it's there, tentatively, until the PR is closed, at which time it may or may not still be there. – torek Feb 15 '19 at 17:56