I need to check if a file exists on the most recent commit (HEAD). I have been doing this with
git cat-file -e HEAD:path/to/file
but I realized this could be problematic if the file has been moved or renamed. Is there a way to check a file based on the SHA? I tried
git cat-file -e SHA
but it seems to search all commits, not just the most recent.
Based on Alan Curry’s answer this seems to work
git ls-tree -r HEAD | grep SHA
You could parse the output of
git ls-tree -r HEAD