Philip Oakley
Philip Oakley

Reputation: 14061

Extract the tree sha1 from a git commit

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.

Upvotes: 3

Views: 1363

Answers (1)

Charlie
Charlie

Reputation: 7349

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

Upvotes: 5

Related Questions