From: ZheNing Hu <adlternative@gmail.com>
To: Vasilij Demyanov <qvasic@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: git download
Date: Fri, 25 Nov 2022 14:06:58 +0800 [thread overview]
Message-ID: <CAOLTT8QF6gqYJf79VQOFn64YD+tew2R2MxjOArm8LZJXC6YbJw@mail.gmail.com> (raw)
In-Reply-To: <CACtGy4i7Jv+UyjwKOLsMOQwUO81=o98AA5SNwi+=xUB76ehD_g@mail.gmail.com>
Hi,
Vasilij Demyanov <qvasic@gmail.com> 于2022年11月24日周四 01:27写道:
>
> 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
next prev parent reply other threads:[~2022-11-25 6:07 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-23 17:17 git download Vasilij Demyanov
2022-11-23 19:14 ` Jacob Keller
2022-11-24 16:52 ` Sean Allred
2022-11-25 6:06 ` ZheNing Hu [this message]
-- strict thread matches above, loose matches on Subject: below --
2017-03-05 20:26 Git download Cory Kilpatrick
2017-03-06 5:33 ` Torsten Bögershausen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAOLTT8QF6gqYJf79VQOFn64YD+tew2R2MxjOArm8LZJXC6YbJw@mail.gmail.com \
--to=adlternative@gmail.com \
--cc=git@vger.kernel.org \
--cc=qvasic@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).