{"thread":{"id":"58846","subject":"git download","startedAt":"2022-11-23T17:17:24Z","lastAt":"2022-11-25T06:07:14Z","messageCount":4,"participants":["Vasilij Demyanov","Jacob Keller","Sean Allred","ZheNing Hu"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"467873","messageId":"CACtGy4i7Jv+UyjwKOLsMOQwUO81=o98AA5SNwi+=xUB76ehD_g@mail.gmail.com","threadId":"58846","inReplyTo":null,"subject":"git download","fromName":"Vasilij Demyanov","fromEmail":"qvasic@gmail.com","sentAt":"2022-11-23T17:17:06Z","receivedAt":"2022-11-23T17:17:24Z","isPatch":false,"sender":{"key":"qvasic@gmail.com","avatar":null},"body":"Hello everybody!\n\nI have a need to get just one file from a repository, it would be\nuseful to have a command something like this:\n\ngit download repo_url branch_or_commit path/to/file\n\nOr maybe there is something like this, I just haven't found it in the docs?\n\nBest regards,\nVasyl\n"},{"id":"467883","messageId":"CA+P7+xoAh3bFBEvVcRF8Xb-DxxWbbM=R0gWVQ6JsFCWtHy4SDw@mail.gmail.com","threadId":"58846","inReplyTo":"CACtGy4i7Jv+UyjwKOLsMOQwUO81=o98AA5SNwi+=xUB76ehD_g@mail.gmail.com","subject":"Re: git download","fromName":"Jacob Keller","fromEmail":"jacob.keller@gmail.com","sentAt":"2022-11-23T19:14:33Z","receivedAt":"2022-11-23T19:14:52Z","isPatch":false,"sender":{"key":"jacob.keller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"On Wed, Nov 23, 2022 at 9:27 AM Vasilij Demyanov <qvasic@gmail.com> wrote:\n>\n> Hello everybody!\n>\n\nHi,\n\n> I have a need to get just one file from a repository, it would be\n> useful to have a command something like this:\n>\n\nOk.\n\n> git download repo_url branch_or_commit path/to/file\n>\n> Or maybe there is something like this, I just haven't found it in the docs?\n>\n\nSo this isn't something git itself provides. Various web hosting\nservices for git provide such access, because they allow viewing the\nrepository contents. Git can't provide this easily because of the\nnature of the commits and trees used to store the contents of the\nrepository. In order to verify that you got the correct contents, you\nessentially have to fetch the commit and all its parents. You can\nmaybe save some download space by using a sparse clone.. but most\nremote repositories may not allow arbitrary commit hash fetching.\n\nIf you already have a repository available from some computer/system\nyou can extract the file at a given version via something like git\ncat-file:\n\n$ git cat-file -p <commitish>:<path>\n\nwhere commitish can be a branch or a commit hash, or other way to\nreference a commit, and path is the path of the file.\n\nUnfortunately you will essentially need to have cloned the repository first.\n\nIf your project is hosted somewhere using software like github,\ngitlab, etc, or has gitweb-like software operating on it, you may be\nable to find an API or web interface that lets you extract the\nindividual file without downloading the repository. This is somewhat\noutside the scope of this mailing list tho.\n\nThanks,\nJake\n\n> Best regards,\n> Vasyl\n"},{"id":"467947","messageId":"87zgcgs2ne.fsf@gmail.com","threadId":"58846","inReplyTo":"CACtGy4i7Jv+UyjwKOLsMOQwUO81=o98AA5SNwi+=xUB76ehD_g@mail.gmail.com","subject":"Re: git download","fromName":"Sean Allred","fromEmail":"allred.sean@gmail.com","sentAt":"2022-11-24T16:52:21Z","receivedAt":"2022-11-24T17:06:44Z","isPatch":false,"sender":{"key":"allred.sean@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2082195?v=4"},"body":"\nVasilij Demyanov <qvasic@gmail.com> writes:\n\n> I have a need to get just one file from a repository, it would be\n> useful to have a command something like this:\n>\n> git download repo_url branch_or_commit path/to/file\n\nMy immediate thought was git-archive[1], but depending the specifics of\nyour needs/setup, you could use curl/wget for this pretty simply. For\nexample, if you're using GitHub, you can\n\n    curl https://raw.githubusercontent.com/git/git/master/README.md\n\nto dump the content of the README to standard out. As another example,\nto get the content of next:builtin/var.c,\n\n    curl https://raw.githubusercontent.com/git/git/next/builtin/var.c\n\nThe general pattern:\n\n    https://raw.githubusercontent.com/<repo>/<branch-or-commit>/<file-path>\n\nGitLab's pattern is similar:\n\n    https://gitlab.com/<repo>/-/raw/<branch-or-commit>/<file-path>\n\ne.g.\n\n    curl https://gitlab.com/gitlab-org/git/-/raw/main/README.md\n\nThis will be limited to getting a single file at a time. If you want\nmore, you can make more curl requests, but git-archive can give a whole\ndirectory or even the entire repo at a specific commit. Since\ngit-archive outputs a tar/zip file, you'll want to combine it with your\nfavorite decompression tool to get your content.\n\n[1]: https://git-scm.com/docs/git-archive\n\n--\nSean Allred\n"},{"id":"467971","messageId":"CAOLTT8QF6gqYJf79VQOFn64YD+tew2R2MxjOArm8LZJXC6YbJw@mail.gmail.com","threadId":"58846","inReplyTo":"CACtGy4i7Jv+UyjwKOLsMOQwUO81=o98AA5SNwi+=xUB76ehD_g@mail.gmail.com","subject":"Re: git download","fromName":"ZheNing Hu","fromEmail":"adlternative@gmail.com","sentAt":"2022-11-25T06:06:58Z","receivedAt":"2022-11-25T06:07:14Z","isPatch":false,"sender":{"key":"adlternative@gmail.com","avatar":"https://avatars.githubusercontent.com/u/58138461?v=4"},"body":"Hi,\n\nVasilij Demyanov <qvasic@gmail.com> 于2022年11月24日周四 01:27写道：\n>\n> Hello everybody!\n>\n> I have a need to get just one file from a repository, it would be\n> useful to have a command something like this:\n>\n> git download repo_url branch_or_commit path/to/file\n>\n> Or maybe there is something like this, I just haven't found it in the docs?\n>\n\nIf the git server support partial-clone (uploadpack.allowFilter),\nmaybe you can use this way:\n\n    git clone --depth=1 --single-branch --branch=main --no-checkout\n--filter=blob:none\ngit@github.com:derrickstolee/sparse-checkout-example.git\n    cd sparse-checkout-example\n    git sparse-checkout set --no-cone \"/README.md\"\n    git checkout main\n\nit will only download single commit, multiple tree, and one blob.\n\nIf the server supports fetch any objects\n(uploadpack.allowAnySHA1InWant) and you already know the\nfile's SHA1, there is a kind of black magic here:\n\n    git init repo\n    cd repo\n    git remote add origin <repo>\n    git -c fetch.negotiationAlgorithm=noop fetch force --no-tags\n--no-write-fetch-head --filter=blob:none --stdin\n    <blob-oid>\n\nYou will get only one blob, \"git cat-file -p <blob-oid>\" to view the\ncontents of this file.\n\nNote these two performance maybe not better than git archive or some\nfile pages support by git server\ndirectly such as\nhttps://raw.githubusercontent.com/derrickstolee/sparse-checkout-example/main/README.md\n\n> Best regards,\n> Vasyl\n\n--\nZheNing Hu\n"}]}