git log
supports looking at the history of specific files (and directories), so you can call it like this:
git log my/file.c
If you really only want to list the one most recent commit, for example to use it in a script, use the -n 1
option:
git log -n 1 --pretty=format:%H -- my/file.c
--pretty=format:%h
tells git log
to show only the commit hash. The --
separater stops the file name from getting interpreted as a commit name, just in case it's ambiguous.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…