I try to find the hash of a file at a given point in the history.
git ls-files $REVISION $PATH | \
sed -n 's/^.\{6\} .\+ \([0-9a-f]\{40\}\)\t.*$/\1/p'
works, but it looks rather inelegant. It displays mode, type, hash and path to then use sed
to filter out only the hash. Is there some command that only prints the hash to begin with?
I imagine to have overlooked something more straightforward like git show --pretty=%hash $REVISION:$PATH
. Does a Git command like this exist?
Git provides the rev-parse
command for printing the SHAs of various items. Unlike many Git commands (pretty much everything but git show
) it uses a colon as a separator between revisions and paths.
git rev-parse $REVISION:$PATH
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With