$ git init
$ date > file1.txt
$ git add .
$ git commit -a -m "ok"
$ git log --raw file1.txt
Last cmd works ok. I get:
:000000 100644 0000000... c0d0a60... A file1.txt
But if I do:
$ git log --raw HEAD:file1开发者_如何学Go.txt
I get nothing.
What am I missing? I need to get the second form working so that I can query the perms of the file in any arbitrary commit, not just the currently checkout working tree.
The log command takes a set-of-commits and a path. In the first form you are giving it a path and set-of-commits defaults to HEAD (all commits reachable from HEAD). In the second form you are giving it an object id that does not name a commit, but is not a path either, so it can't do anything.
You need to give it a commit set and the path:
- Commit set containing just one commit is
commitish^!
. So in your caseHEAD^!
. - Path is still just
file1.txt
So use:
git log --raw HEAD^! file1.txt
Of course (as J-16 SDiZ correctly noted) using git ls-tree
, which is designed for the purpose, is better than abusing git log
. So that would be:
git ls-tree HEAD file1.txt
unlike log
, ls-tree
takes a treeis (of which a commitish is a special-case), so you don't have to add funny suffixes like ^!
.
You need:
git log --raw HEAD^1..HEAD file1.txt
精彩评论