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

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.


Update: @Markonius' answer is the proper way to do it.

Here is a script that does this based on experimenting with an LFS repository. I didn't look at the LFS protocol in details, so there might be quirks unaccounted for, but it worked for my simple case.

git-lfs-cat-file

The relevant details are:

  • LFS files are stored in the index with the following structure:

    version https://git-lfs.github.com/spec/v1
    oid sha256:abcdeffffffffffffff
    size nnnnnnnn
    
  • Actual LFS object will then be under .git/lfs/objects/ab/cd/abcdeffffffffffffff.

Tags:

Git

Git Lfs