Is there a good way to get a git hash that works as follows:
git commit -a -m ''
?Background:
I'm writing some development tools that package up builds. I'd like the build package to include some sort of reasonably-robust and completely automatic version id. A git SHA1 hash is more than sufficient for my purposes. Unfortunately, just using git rev-parse HEAD
isn't sufficient because users will commonly run the build before committing, and thus before HEAD
is updated.
Create a temporary index, write the uncommitted changes to it, then get the sha of that tree.
cp .git/index /tmp/git_index
export GIT_INDEX_FILE=/tmp/git_index
git add -u
git write-tree
This will print out a sha unique to the current state of the git repo including uncommitted changes, but not including new files.
I think you want the hash of a Git tree object, not that of a commit. A commit hash depends on the commit time and will be different every time you compute it.
To create a new tree object from your working copy you can run the write-tree
command:
git add -u && git write-tree && git reset
Note that this will mess up your index (as it will temporarily stage all changes)
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