Reputation: 5061
$ git add somefile.txt
$ TREE_HASH_PREDICTION=$(???)
$ git commit -m "some message"
$ TREE_HASH=$(git rev-parse HEAD^{tree})
assuming commit doesn't trigger any hooks that add further files or remove some from the staging area, what command can I use in ??? so that TREE_HASH_PREDICTION will match TREE_HASH?
Note: I'm NOT asking about the commit hash, but about the tree hash contained in the commit
Upvotes: 3
Views: 111
Reputation: 308001
git write-tree
ensures that there is a tree object with the context of the current index (i.e. staged changes) and writes out the id of that object. Absent any modifications after this (i.e. commit hooks), this tree object will be the one that's used in the commit.
Note that this actually creates files on disk that hold the content of that tree, which costs time and IO. But that time used should also be saved during the commit, as it won't have to be re-created and if you end up not committing the changes the GC will probably remove that tree object eventually.
Upvotes: 5