Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract the tree sha1 from a git commit

Tags:

git

shell

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.

like image 617
Philip Oakley Avatar asked May 08 '26 04:05

Philip Oakley


1 Answers

What about git checkout master followed by git rev-parse HEAD^{tree} ?

like image 145
Charlie Avatar answered May 09 '26 23:05

Charlie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!