Hi, Vasilij Demyanov <qvasic@xxxxxxxxx> 于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@xxxxxxxxxx: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