Git fetch a specific commit by hash

前端 未结 3 1878
北荒
北荒 2020-12-10 11:40

Git allows to fetch from any given remote and reference, for example

git fetch  

So that those given com

相关标签:
3条回答
  • 2020-12-10 11:52

    See "Pull a specific commit from a remote git repository":
    With Git 2.5 (July 2015), you will be able to do:

    git fetch --depth=1 <a/remote/repo.git> $SHA1
    git cat-file commit $SHA1
    

    If the SHA1 is "reachable" from one of the branch tips of the remote repo, then you can fetch it.

    Caveat: you need a Git 2.5 remote repo server though, which will handle the uploadpack.allowReachableSHA1InWant config (and you need that config to be set to true, in order to allow a single commit fetch).

    0 讨论(0)
  • 2020-12-10 12:00

    As today I tried:

    git fetch origin <commit-hash>
    

    And it works like a charm! (git version 2.20.1)

    Just be sure the <commit-hash> is the full length reference

    0 讨论(0)
  • 2020-12-10 12:16

    No. According to the manual, git fetch wants a refspec, the simplest form of which is a ref, and a bare SHA-1 isn't a ref. I.e., the commit has to have a name (branch, tag) on the remote for you to be able to fetch it.

    0 讨论(0)
提交回复
热议问题