我正在尝试查看 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
我做错了什么?
最佳答案
这里的问题是 54a6fa4542a4ae26d5a8155b63a50701ab69c1f8
在 https://github.com/Miserlou/Zappa
的存储库中只有一半。
也就是说,如果您克隆 https://github.com/Miserlou/Zappa
,您将获得一个有效的存储库,其中的提交数略低于 3000。 54a6fa4542a4ae26d5a8155b63a50701ab69c1f8
不是这些提交之一。
事实上,54a6fa4542a4ae26d5a8155b63a50701ab69c1f8
是另一个 存储库中的提交。您可以在 https://github.com/Miserlou/Zappa/pull/1762
中看到这一点,其中显示:
Open purificant wants to merge 1 commit into Miserlou:master from purificant:py37
因此,此提交更适合在分支名称 py37
下由 purificant
拥有的分支中进行(将鼠标悬停在一些标签上,您将在 pop 窗口)。
但是,一旦有人在 GitHub 上发出 pull 请求,这些提交也可以通过目标存储库获得。只需要一点技巧:
git fetch origin refs/pull/1762/head:refs/heads/pr1762
现在 git show 54a6fa4542a4ae26d5a8155b63a50701ab69c1f8
和 git checkout 54a6fa4542a4ae26d5a8155b63a50701ab69c1f8
工作。
$ 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
(我不清楚不是我的人怎么会想出这个。:-))
(我在这里使用的原始名称 pr1762
不是一个好名字,我已经将其编辑为改为阅读 refs/heads/pr1762
。)
关于git - 我如何从 Github checkout 特定的提交?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54712844/