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

Re: git download

From
Jacob Keller <jacob.keller@gmail.com>
Date
Nov 23, 2022, 19:14 UTC
Message-ID
<CA+P7+xoAh3bFBEvVcRF8Xb-DxxWbbM=R0gWVQ6JsFCWtHy4SDw@mail.gmail.com>
In-Reply-To
<CACtGy4i7Jv+UyjwKOLsMOQwUO81=o98AA5SNwi+=xUB76ehD_g@mail.gmail.com>
On Wed, Nov 23, 2022 at 9:27 AM Vasilij Demyanov <qvasic@gmail.com> wrote:
>
> Hello everybody!
>
Hi,
> I have a need to get just one file from a repository, it would be
> useful to have a command something like this:
>
Ok.
> 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?
>

So this isn't something git itself provides. Various web hosting services for git provide such access, because they allow viewing the repository contents. Git can't provide this easily because of the nature of the commits and trees used to store the contents of the repository. In order to verify that you got the correct contents, you essentially have to fetch the commit and all its parents. You can maybe save some download space by using a sparse clone.. but most remote repositories may not allow arbitrary commit hash fetching.

If you already have a repository available from some computer/system you can extract the file at a given version via something like git cat-file:

$ git cat-file -p <commitish>:<path>

where commitish can be a branch or a commit hash, or other way to reference a commit, and path is the path of the file.

Unfortunately you will essentially need to have cloned the repository first.

If your project is hosted somewhere using software like github, gitlab, etc, or has gitweb-like software operating on it, you may be able to find an API or web interface that lets you extract the individual file without downloading the repository. This is somewhat outside the scope of this mailing list tho.

Thanks, Jake

> Best regards,
> Vasyl
Previous: Vasilij DemyanovNext: Sean Allred
Message 2 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.