gitgit-lfs

Get file path from git lfs object hash


I'm currently faced with a git lfs error that prevents me from pushing a local commit to the remote server. The error message contains the hash of a potentially problematic git lfs object, but not its corresponding file path in the working tree. How would I be able to obtain the path of this problematic file from its git lfs hash so I can take a closer look at it?

Here is the full error message for reference (URLs edited to comply with my employer's NDA):

LFS: Client error: https://dev.azure.com/my_organization/my_project/_git/my_repository/info/lfs/objects/9bf017ecdcfe64013cf704f92e145f47e5f91792f8a8eee791af9b730392d590 from HTTP 413
error: failed to push some refs to 'https://dev.azure.com/my_organization/my_project/_git/my_repository'

I already tried the shell script from this stackoverflow answer, but it doesn't seem to print any results if I call it with my object hash (./git-hash-to-filepath.sh f56f7109f17b227a830d9edc24e447a0637bebba409527c24007c68a1c400cc8).


Solution

  • The question you point to gives a way to look for blobs stored in git (not in lfs).

    I am not 100% familiar with the details of git lfs, I think your files get replaced, in git storage, with a text file which contains the id you see (9bf017ecd...)

    If that is the case, you may try on of the pickaxe options (-S or -G) of git log to spot the commits where this id appeared or disappeared:

    git log --graph --oneline -G 9bf017ecdcfe64013cf704f92e145f47e5f91792f8a8eee791af9b730392d590
    
    # to view which file(s) contain that string, add --name-only or --name-status
    git log --name-status --graph --oneline -G 9bf017ecdcfe64013cf704f92e145f47e5f91792f8a8eee791af9b730392d590
    

    link to doc: git help log, -S and -G section