Re: Can I fetch an arbitrary commit by sha1?
From: Dan Johnson <hidden>
Date: 2016-06-15 23:02:38
On Thu, Oct 2, 2014 at 9:57 AM, Christian Halstrick [off-list ref] wrote:
I always though during fetch I have to specify a refspec and that a sha1 would not be accepted as a ref. Firing some like 'git fetch origin <sha1>' should be forbidden. But in fact I see that such a fetch command succeeds if you already have that object in your local repo. My question: is it allowed to fetch sha1's? Shouldn't fetch fail if you try it? See here:quoted
git clone -q https://github.com/chalstrick/dondalfi.git cd dondalfi git ls-remoteFrom https://github.com/chalstrick/dondalfi.git ce08dcc41104383f3cca2b95bd41e9054a957f5b HEAD af00f4c39bcc8dc29ed8f59a47066d5993c279e4 refs/foo/b1 ...quoted
git show af00f4c39bcc8dc29ed8f59a47066d5993c279e4fatal: bad object af00f4c39bcc8dc29ed8f59a47066d5993c279e4quoted
git fetch origin af00f4c39bcc8dc29ed8f59a47066d5993c279e4error: no such remote ref af00f4c39bcc8dc29ed8f59a47066d5993c279e4quoted
git fetch origin refs/foo/b1remote: Counting objects: 3, done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (3/3), done. From https://github.com/chalstrick/dondalfi * branch refs/foo/b1 -> FETCH_HEADquoted
git fetch origin af00f4c39bcc8dc29ed8f59a47066d5993c279e4From https://github.com/chalstrick/dondalfi * branch af00f4c39bcc8dc29ed8f59a47066d5993c279e4 -> FETCH_HEAD
My understanding is that you are allowed to ask for a SHA1, but most git servers refuse the request. But if you already have the SHA locally, then git doesn't neet to bother asking the server for it, so there's no request to be refused. But it's been a while for me since I did any git development, so it's possible I missed something. -Dan