Let’s say as part of the build process for a website, I copy a git project to a web-accessible directory and remove the .git directory. Now, a few days later after I’m a few commits ahead of the public web directory, what’s a simple way to figure out which version of /index.html is currently being served?
# /var/www (public web dir):
/index.html
# Git repository:
HEAD:/index.html
HEAD~1:/index.html
HEAD~2:/index.html
.
. <-- /var/www/index.html matches in here somewhere.
.
HEAD~N:/index.html
The only thing I can think to do is write a script to checkout every version of the file in git and check each one, but in my limited experience with git I’ve found that there is usually some canonical way to accomplish whatever git task I dream up.
Using git-describe is a good idea. Also, you might consider using git-archive to generate a tarball rather than cloning the git repository and then deleting the .git directory. Keep the archive around and use git-get-commit-tar-id to find the commit. To answer your actual question, use git-hash-object to get the blob of the file in question, then see the answers to this Which commit has this blob?