简体   繁体   中英

How can I checkout a github commit from outside a branch

To be specific, my goal is to have access to this specific commit https://github.com/ankidroid/Anki-Android/commit/73afde67830bb6e49388d0e3a135e945fdbbfc4a

The issue is that the commit is outside a specific branch. So I can't just fetch its branch. git fetch ankidroid 73afde6 (where ankidroid is my local name for this remote) or git pull ankidroid 73afde6 fails. If I do git fetch the command at least succeed, but the commit 73afde6 is still not known.

Some hosting sites won't allow you to fetch a commit by its hash ID. If you are using such a hosting site, you must find some name that will allow fetching the commit. Fortunately for you, you are using , which does allow fetching by raw hash ID. 1

The trick is that you must use the full hash ID . That is, run:

git fetch ankidroid 73afde67830bb6e49388d0e3a135e945fdbbfc4a

The command:

git fetch ankidroid 73afde6

does not suffice.

(You might want to give the commit a name you can refer to in your local repository, eg, git fetch ankidroid 73afde67830bb6e49388d0e3a135e945fdbbfc4a:refs/heads/foo . This creates a new branch name foo in your local repository, pointing to the fetched commit. This assumes you do not currently have a branch named foo ; if so, substitute in some other name.)


1 The new partial clone feature requires this, so it's becoming more common.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM