Retrieve specific commit from a remote Git repository

后端 未结 10 1878
谎友^
谎友^ 2020-11-22 06:32

Is there any way to retrieve only one specific commit from a remote Git repo without cloning it on my PC? The structure of remote repo is absolutely same as that of mine and

10条回答
  •  时光说笑
    2020-11-22 06:51

    You can simply fetch a single commit of a remote repo with

    git fetch  
    

    where,

    • can be a remote repo name (e.g. origin) or even a remote repo URL (e.g. https://git.foo.com/myrepo.git)
    • can be the SHA1 commit

    for example

    git fetch https://git.foo.com/myrepo.git 0a071603d87e0b89738599c160583a19a6d95545
    

    after you fetched the commit (and the missing ancestors) you can simply checkout it with

    git checkout FETCH_HEAD
    

    Note that this will bring you in the "detached head" state.

提交回复
热议问题