$ git init
$ echo zero > a
$ git add a
$ git commit -m zero
$ echo other > a
$ git add a
$ git commit -m other
$ echo whatever > a
$ git add a
$ git commit -m whatever
I’m checking out the file as it was when I commited the 2nd time, when the file contained the text other.
$ git checkout HASH_OF_COMMIT_OTHER a
$ cat a
other
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: a
#
What command should I run on a, so that git will tell at which changeset it currently is? In this case I would like it to show me the hash of the 2nd commit, along with the commit message, if possible.
Once you’ve run the command
git checkout HASH_OF_COMMIT_OTHER a, the working tree and the index are updated with the version ofafromHASH_OF_COMMIT, but there’s no record preserved of how the file was changed to be in that state. This is part of git’s philosophy of tracking content – it doesn’t matter how the file got into the state it is at a certain commit, it just records the exact content of the files at each one.You could certainly write a short script to find all commits that contained a file with exactly that content (and at that path) if you like, but normally one wouldn’t need to.