0

I have a repository and it has LFS files. I want to retrieve a particular LFS tracked file from a previuos commit, without affecting the working directory.

In other words, if I were to retrieve a non-LFS file (simple text file) from a previous commit, without changing the current working directory in anyway, I could do this:

git ls-tree -l -r <commit_id> | grep some_file.txt
git cat-file blob <blob_id> > some_external_directory_path/some_file.txt # blob_id is obtained from the previous command's output

What can be the equivalent for an LFS file? Because in the above way, only the file with LFS SHA details is retrieved, not the actual file.

anupamb
  • 472
  • 4
  • 13
  • Inside that blob, you will find an OID which identifies the file to download from the lfs file server. – LeGEC Jul 24 '20 at 21:36

1 Answers1

0

You can do this with git cat-file --filters BLOB_ID. Note that you can also wrie this as git cat-file --filters COMMIT_ID:some_file.txt.

Using the --filters option applies filters, such as Git LFS, to the blob. It can also be used for non-LFS blobs if you want a version of the blob with line ending or encoding changes applied.

bk2204
  • 64,793
  • 6
  • 84
  • 100