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 mainit 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