Retrieve specific commit from a remote Git repository

后端 未结 10 1837
谎友^
谎友^ 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:52

    You can simply fetch the 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)

    for example:

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

    after you fetched the repos you may merge the commits that you want (since the question is about retrieve one commit, instead merge you may use cherry-pick to pick just one commit):

    git merge 
    
    • can be the SHA1 commit

    for example:

    git cherry-pick 0a071603d87e0b89738599c160583a19a6d95545
    

    or

    git merge 0a071603d87e0b89738599c160583a19a6d95545
    

    if is the latest commit that you want to merge, you also may use FETCH_HEAD variable :

    git cherry-pick (or merge) FETCH_HEAD
    

提交回复
热议问题