216 points · by matheust · 2y ago · 22 comments
git archive --remote=ssh://host/pathto/repo.git HEAD README.md | tar xO
Though apparently support depends on how you're running git, and potentially some enabled server side options.[1] https://stackoverflow.com/questions/1125476/retrieve-a-singl...
git clone --filter=tree:0 --depth=1 --sparse --no-checkout && git checkout HEAD <desired_file>
(But that would still end up fetching a few more objects than just the desired file.)
(I would assume git doesn't trust the server, and will verify that the chain of hashes works out.)
"Fun" is a good reason for this sort or exploration, but it also has its practical uses. For instance, I use `isomorphic-git` (a git client written in JavaScript) to include a comment with the relevant commit hash in my bundled JavaScript. I can run it on any machine with Node, without opening a shell or trying to find where/if git is installed locally.
Blog posts are becoming my favourite form of knowledge transfer
I’ve been meaning to start one myself and posts like this are making me move it up my todo list
A few months ago I figured out how to modify remote refs in a similar fashion although I wrote it in go. https://stackoverflow.com/a/77210784/308851
$ TEST_VAR="$(printf 'first\0second')"
bash: warning: command substitution: ignored null byte in input
I'm not familiar with working with null characters in Bash in this way, but I think there might be a way to do it.One option with shells is some set/get functions that encode/decode to base64, hex, etc. Feels pretty clunky though.