Another title for this question could be 'How to checkout multiple versions of a Git-LFS managed file?'
I would like to inspect several versions of a file stored in Git-LFS. I would therefore like to several versions of this file side-by-side in my working directory. Something like this is what I have in mind:
git show v1:./myfile.ipynb > myfile-v1.ipynb
git show v2:./myfile.ipynb > myfile-v2.ipynb
This does not work as desired: the file is managed by Git-LFS, so to git show
its contents at each version looks like
version https://git-lfs.github.com/spec/v1
oid sha256:62aafe00ec8b61a37dd729e7d3a723382...
size 20439
I am interested in the file's 'true', Git-LFS-managed contents, rather than the pointer file that LFS stores in Git's own tree.
How can I create untracked, custom-named files that each contain a specific version of a file tracked by Git-LFS? This does not need to be a single command, I am resigned to Git needing multi-step scripts for single-concept actions.
git checkout recovers old versions of files.
Piping an lfs pointer into git lfs smudge
will yield you what you want. For example:
git cat-file blob <blob-sha> | git lfs smudge
Or if you have a commit-ish (a commit hash, branch name, just HEAD
, etc.) and a file name:
git cat-file blob <commit-ish>:path/to/my-large-file.name | git lfs smudge
You could redirect the output into a file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With