I'm looking the extract the top level tree's sha1 from a git commit, usually from a branch tip.
Is there a more effective portable command sequence than
git cat-file -p master | egrep -e "^tree [a-f0-9]{40}$" | head -1 | cut -c6-45 ?
Here its the top level tree of the master branch. This needs to be portable across Mysgit as well as regular Linux. The object sha1 value will be assigned to a variable for further processing.
The need to pipe through three extra commands after the git cat-file does feel excessive.
What about git checkout master followed by git rev-parse HEAD^{tree} ?
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