git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git download

From
ZheNing Hu <adlternative@gmail.com>
Date
Nov 25, 2022, 06:06 UTC
Message-ID
<CAOLTT8QF6gqYJf79VQOFn64YD+tew2R2MxjOArm8LZJXC6YbJw@mail.gmail.com>
In-Reply-To
<CACtGy4i7Jv+UyjwKOLsMOQwUO81=o98AA5SNwi+=xUB76ehD_g@mail.gmail.com>
Hi,
Vasilij Demyanov <qvasic@gmail.com> 于2022年11月24日周四 01:27写道:
Show 10 quoted lines
>
> Hello everybody!
>
> I have a need to get just one file from a repository, it would be
> useful to have a command something like this:
>
> git download repo_url branch_or_commit path/to/file
>
> Or maybe there is something like this, I just haven't found it in the docs?
>

If the git server support partial-clone (uploadpack.allowFilter), maybe you can use this way:

    git clone --depth=1 --single-branch --branch=main --no-checkout
--filter=blob:none
git@github.com:derrickstolee/sparse-checkout-example.git
    cd sparse-checkout-example
    git sparse-checkout set --no-cone "/README.md"
    git checkout main
it will only download single commit, multiple tree, and one blob.

If the server supports fetch any objects (uploadpack.allowAnySHA1InWant) and you already know the file's SHA1, there is a kind of black magic here:

    git init repo
    cd repo
    git remote add origin <repo>
    git -c fetch.negotiationAlgorithm=noop fetch force --no-tags
--no-write-fetch-head --filter=blob:none --stdin
    <blob-oid>

You will get only one blob, "git cat-file -p <blob-oid>" to view the contents of this file.

Note these two performance maybe not better than git archive or some file pages support by git server directly such as https://raw.githubusercontent.com/derrickstolee/sparse-checkout-example/main/README.md

> Best regards,
> Vasyl

-- ZheNing Hu

Previous: Sean Allred
Message 4 of 4 in “git download”
  1. Vasilij DemyanovNov 23, 2022
  2. Jacob KellerNov 23, 2022
  3. Sean AllredNov 24, 2022
  4. ZheNing HuNov 25, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.