Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print a Git LFS file's old version to stdout (git show / git cat-file for LFS)?

Tags:

git

git-lfs

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.

like image 844
Esteis Avatar asked Jun 08 '18 12:06

Esteis


People also ask

Which command is used to explore the previous versions of a project?

git checkout recovers old versions of files.


1 Answers

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.

like image 165
markonius Avatar answered Oct 18 '22 21:10

markonius