{"thread":{"id":"27140","subject":"Cloning a remote tag without using git-fetch-pack directly?","startedAt":"2011-04-19T22:20:53Z","lastAt":"2011-04-20T07:40:17Z","messageCount":5,"participants":["Josh Triplett","Jeff King","Jonathan Nieder"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"166109","messageId":"20110419222050.GA3304@feather","threadId":"27140","inReplyTo":null,"subject":"Cloning a remote tag without using git-fetch-pack directly?","fromName":"Josh Triplett","fromEmail":"josh@joshtriplett.org","sentAt":"2011-04-19T22:20:53Z","receivedAt":"2011-04-19T22:20:53Z","isPatch":false,"sender":{"key":"josh@joshtriplett.org","avatar":"https://avatars.githubusercontent.com/u/162737?v=4"},"body":"Using fetch-pack, I can clone a single tag from a repository:\n\n/tmp/testrepo$ git init\nInitialized empty Git repository in /tmp/testrepo/.git/\n/tmp/testrepo$ git fetch-pack /home/josh/src/linux-2.6/.git refs/tags/v2.6.12\nremote: Counting objects: 31617, done.\nremote: Compressing objects: 100% (21083/21083), done.\nReceiving objects: 100% (31617/31617), 52.56 MiB | 5.27 MiB/s, done.\nremote: Total 31617 (delta 12862), reused 19495 (delta 10331)\nResolving deltas: 100% (12862/12862), done.\nkeep    c80bd1def293bc11591159c96970d8becfe3b2d9\n26791a8bcf0e6d33f43aef7682bdb555236d56de refs/tags/v2.6.12\n/tmp/testrepo$ git show 26791a8bcf0e6d33f43aef7682bdb555236d56de | head -20\ntag v2.6.12\n\nThis is the final 2.6.12 release\n-----BEGIN PGP SIGNATURE-----\nVersion: GnuPG v1.2.4 (GNU/Linux)\n\niD8DBQBCsykyF3YsRnbiHLsRAvPNAJ482tCZwuxp/bJRz7Q98MHlN83TpACdHr37\no6X/3T+vm8K3bf3driRr34c=\n=sBHn\n-----END PGP SIGNATURE-----\n\ncommit 9ee1c939d1cb936b1f98e8d81aeffab57bae46ab\nAuthor: Linus Torvalds <torvalds@ppc970.osdl.org>\nDate:   Fri Jun 17 12:48:29 2005 -0700\n\n    Linux 2.6.12\n\ndiff --git a/Makefile b/Makefile\nindex 9e005e1..0d1e74d 100644\n--- a/Makefile\n\n\n\nHowever, I can't seem to find any way to convince git clone to do the\nsame thing for me.  git clone will clone a branch, but not a tag.\n\n/tmp/testrepo$ git clone /home/josh/src/linux-2.6/.git -b refs/tags/v2.6.12\nCloning into linux-2.6...\ndone.\nwarning: Remote branch refs/tags/v2.6.12 not found in upstream origin, using HEAD instead\n\n\nOn a different note, git fetch-pack seems to silently fail if asked to\nfetch a remote tag which points at a tree object rather than a commit\nobject:\n\n/tmp/testrepo$ git init\nInitialized empty Git repository in /tmp/testrepo/.git/\n/tmp/testrepo$ git fetch-pack /home/josh/src/linux-2.6/.git refs/tags/v2.6.12-tree\n(1) /tmp/testrepo$ echo $?\n1\n\n\nI realize that I want to do something strange here, but it seems like a\nkind of strange that git already supports in at least some ways, just\nnot in others.  Am I missing something?\n\nThanks,\nJosh Triplett\n"},{"id":"166129","messageId":"20110420062653.GE28597@sigill.intra.peff.net","threadId":"27140","inReplyTo":"20110419222050.GA3304@feather","subject":"Re: Cloning a remote tag without using git-fetch-pack directly?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-04-20T06:26:54Z","receivedAt":"2011-04-20T06:26:54Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Apr 19, 2011 at 03:20:53PM -0700, Josh Triplett wrote:\n\n> Using fetch-pack, I can clone a single tag from a repository:\n> \n> /tmp/testrepo$ git init\n> Initialized empty Git repository in /tmp/testrepo/.git/\n> /tmp/testrepo$ git fetch-pack /home/josh/src/linux-2.6/.git refs/tags/v2.6.12\n\nI don't think there is any reason to use fetch-pack here instead of\nfetch. The latter will handle other non-git protocols like dumb http and\ngit-over-http.\n\n> However, I can't seem to find any way to convince git clone to do the\n> same thing for me.  git clone will clone a branch, but not a tag.\n> \n> /tmp/testrepo$ git clone /home/josh/src/linux-2.6/.git -b refs/tags/v2.6.12\n> Cloning into linux-2.6...\n> done.\n> warning: Remote branch refs/tags/v2.6.12 not found in upstream origin, using HEAD instead\n\nRight. There is no way to do what you want with clone. The \"-b\" option\nis not \"just clone this one thing\", it is \"clone everything, but the\nbranch I am interested in is ...\". The fetch refspec remains\n\"+refs/heads/*:refs/remotes/origin/*\".\n\nTo clone a subset of a repository, you have to do the init+fetch trick,\nas you did above.  If you want the configuration set up by clone, you\ncan do that, too, with \"git config\". So the equivalent commands to the\nclone you want are:\n\n  git init linux-2.6\n  cd linux-2.6\n  git config remote.origin.url /home/josh/src/linux-2.6\n  git config remote.origin.fetch refs/tags/v2.6.12\n  git fetch origin\n\nWe could make clone more flexible with respect to such things, but I\ndon't know how useful that would be. A very small minority of power\nusers want to use weird fetch refspecs, and it is simple enough to\nconfigure them manually, as above.\n\n> On a different note, git fetch-pack seems to silently fail if asked to\n> fetch a remote tag which points at a tree object rather than a commit\n> object:\n> \n> /tmp/testrepo$ git init\n> Initialized empty Git repository in /tmp/testrepo/.git/\n> /tmp/testrepo$ git fetch-pack /home/josh/src/linux-2.6/.git refs/tags/v2.6.12-tree\n> (1) /tmp/testrepo$ echo $?\n> 1\n\nDid you mean v2.6.11-tree? There is no v2.6.12-tree in standard\nlinux-2.6 repositories. So fetch-pack is failing because there are no\nmatching refs to fetch. This works for me:\n\n  $ git init\n  $ git fetch-pack /home/peff/compile/linux-2.6 refs/tags/v2.6.11-tree\n  remote: Counting objects...\n  ...\n\nIf you want better error messages, use the fetch porcelain:\n\n  $ git init\n  $ git fetch /home/peff/compile/linux-2.6 refs/tags/v2.6.12-tree\n  fatal: Couldn't find remote ref refs/tags/v2.6.12-tree\n  fatal: The remote end hung up unexpectedly\n\n-Peff\n"},{"id":"166132","messageId":"20110420072720.GC1790@feather","threadId":"27140","inReplyTo":"20110420062653.GE28597@sigill.intra.peff.net","subject":"Re: Cloning a remote tag without using git-fetch-pack directly?","fromName":"Josh Triplett","fromEmail":"josh@joshtriplett.org","sentAt":"2011-04-20T07:27:20Z","receivedAt":"2011-04-20T07:27:20Z","isPatch":false,"sender":{"key":"josh@joshtriplett.org","avatar":"https://avatars.githubusercontent.com/u/162737?v=4"},"body":"On Wed, Apr 20, 2011 at 02:26:54AM -0400, Jeff King wrote:\n> On Tue, Apr 19, 2011 at 03:20:53PM -0700, Josh Triplett wrote:\n> \n> > Using fetch-pack, I can clone a single tag from a repository:\n> > \n> > /tmp/testrepo$ git init\n> > Initialized empty Git repository in /tmp/testrepo/.git/\n> > /tmp/testrepo$ git fetch-pack /home/josh/src/linux-2.6/.git refs/tags/v2.6.12\n> \n> I don't think there is any reason to use fetch-pack here instead of\n> fetch. The latter will handle other non-git protocols like dumb http and\n> git-over-http.\n> \n> > However, I can't seem to find any way to convince git clone to do the\n> > same thing for me.  git clone will clone a branch, but not a tag.\n> > \n> > /tmp/testrepo$ git clone /home/josh/src/linux-2.6/.git -b refs/tags/v2.6.12\n> > Cloning into linux-2.6...\n> > done.\n> > warning: Remote branch refs/tags/v2.6.12 not found in upstream origin, using HEAD instead\n> \n> Right. There is no way to do what you want with clone. The \"-b\" option\n> is not \"just clone this one thing\", it is \"clone everything, but the\n> branch I am interested in is ...\". The fetch refspec remains\n> \"+refs/heads/*:refs/remotes/origin/*\".\n\nOh, good to know; I hadn't yet figured out that -b didn't change the\nrefspec.\n\n> To clone a subset of a repository, you have to do the init+fetch trick,\n> as you did above.  If you want the configuration set up by clone, you\n> can do that, too, with \"git config\". So the equivalent commands to the\n> clone you want are:\n> \n>   git init linux-2.6\n>   cd linux-2.6\n>   git config remote.origin.url /home/josh/src/linux-2.6\n>   git config remote.origin.fetch refs/tags/v2.6.12\n>   git fetch origin\n> \n> We could make clone more flexible with respect to such things, but I\n> don't know how useful that would be. A very small minority of power\n> users want to use weird fetch refspecs, and it is simple enough to\n> configure them manually, as above.\n\nI'd certainly appreciate having a \"git clone --refspec=...\" or similar,\nbut thanks for suggesting fetch rather than fetch-pack!  I actually\ndon't always want the remote set up for this particular purpose, so\nusing fetch works out well.\n\n> > On a different note, git fetch-pack seems to silently fail if asked to\n> > fetch a remote tag which points at a tree object rather than a commit\n> > object:\n> > \n> > /tmp/testrepo$ git init\n> > Initialized empty Git repository in /tmp/testrepo/.git/\n> > /tmp/testrepo$ git fetch-pack /home/josh/src/linux-2.6/.git refs/tags/v2.6.12-tree\n> > (1) /tmp/testrepo$ echo $?\n> > 1\n> \n> Did you mean v2.6.11-tree? There is no v2.6.12-tree in standard\n> linux-2.6 repositories. So fetch-pack is failing because there are no\n> matching refs to fetch. This works for me:\n> \n>   $ git init\n>   $ git fetch-pack /home/peff/compile/linux-2.6 refs/tags/v2.6.11-tree\n>   remote: Counting objects...\n>   ...\n> \n> If you want better error messages, use the fetch porcelain:\n> \n>   $ git init\n>   $ git fetch /home/peff/compile/linux-2.6 refs/tags/v2.6.12-tree\n>   fatal: Couldn't find remote ref refs/tags/v2.6.12-tree\n>   fatal: The remote end hung up unexpectedly\n\nWell, *that's* embarassing.  I thought I'd tested that with a couple of\nother repositories and tree-tag objects, but apparently not.\n\nSadly, though, I still can't check out the result:\n\n/tmp/linux-2.6$ git checkout FETCH_HEAD\nfatal: Cannot switch branch to a non-commit.\n(128) /tmp/linux-2.6$ git checkout -b master FETCH_HEAD\nfatal: Cannot switch branch to a non-commit.\n\nI guess I'd hoped for something similar to \"detached HEAD\" mode.\n\nBased on this, I need still to switch to using faked commits rather than\ntrees.\n\n- Josh Triplett\n"},{"id":"166135","messageId":"20110420073805.GA2285@sigill.intra.peff.net","threadId":"27140","inReplyTo":"20110420072720.GC1790@feather","subject":"Re: Cloning a remote tag without using git-fetch-pack directly?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-04-20T07:38:05Z","receivedAt":"2011-04-20T07:38:05Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Apr 20, 2011 at 12:27:20AM -0700, Josh Triplett wrote:\n\n> Sadly, though, I still can't check out the result:\n> \n> /tmp/linux-2.6$ git checkout FETCH_HEAD\n> fatal: Cannot switch branch to a non-commit.\n> (128) /tmp/linux-2.6$ git checkout -b master FETCH_HEAD\n> fatal: Cannot switch branch to a non-commit.\n> \n> I guess I'd hoped for something similar to \"detached HEAD\" mode.\n\nNo, it wouldn't make any sense to have a non-commit in HEAD, detached or\notherwise, since you couldn't build commits on top of it (what would the\nnew commit's parent pointer have in it?).\n\nIf you just want to check the files out into the working tree, you can\ndo:\n\n  git read-tree --reset -u FETCH_HEAD\n\nBut I'm not really clear on what you're trying to accomplish with all of\nthis. If you can describe your ultimate goal, I might be able to help\nmore.\n\n-Peff\n"},{"id":"166136","messageId":"20110420073955.GA809@elie","threadId":"27140","inReplyTo":"20110420062653.GE28597@sigill.intra.peff.net","subject":"Re: Cloning a remote tag without using git-fetch-pack directly?","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-04-20T07:40:17Z","receivedAt":"2011-04-20T07:40:17Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hi,\n\nSome quick additional thoughts.\n\nJeff King wrote:\n\n> To clone a subset of a repository, you have to do the init+fetch trick,\n> as you did above.  If you want the configuration set up by clone, you\n> can do that, too, with \"git config\". So the equivalent commands to the\n> clone you want are:\n>\n>   git init linux-2.6\n>   cd linux-2.6\n>   git config remote.origin.url /home/josh/src/linux-2.6\n>   git config remote.origin.fetch refs/tags/v2.6.12\n>   git fetch origin\n\nSomeone fetching v2.6.12 to build on it today is probably not planning\nto run \"git fetch origin\" to fetch the same tag tomorrow.  So\n\n\tgit init linux-2.6\n\tcd linux-2.6\n\tgit remote add origin ~/src/linux-2.6\n\tgit fetch origin refs/tags/v2.6.12\n\nor even \"...; git fetch ~/src/linux-2.6 refs/tags/v2.6.12\" could be\ncloser to what is needed.\n\nIf for some reason you do want to track how the remote v2.6.12 tag\nevolves, \"git remote\" has a funny way to do that:\n\n\tgit remote add --mirror=fetch -ttags/v2.6.12 origin ~/src/linux.2.6\n\nThe documentation calls the argument to -t \"<branch>\", but in mirror\nmode it is actually a refspec relative to refs/.\n\nWith luck (depending on what you are looking to do),\ngit-new-workdir[1] or \"git archive --remote\" could also be helpful.\n\nRegards,\nJonathan\n\n[1] with the usual avoidable caveats described at\nhttps://git.wiki.kernel.org/index.php/SoC2011Ideas#Multiple_work_trees\n"}]}