Question

Does anyone knows if Git can give you a hash for the current code on the local machine.

basically, a SHA1 hash of the entire filesystem acknowledged by GIT (a.k.a leaving untracked files out), maybe leaving also file permissions out?

Been looking for it, but was not able to find it.

I've made the classic mistake of make a modification on production server and then make a commit and now i want to kill myself.

regards

Was it helpful?

Solution

There's a quick and dirty checksum available for the complete tree contents of any commit (which by definition includes tracked files only, but does also include the execute bits for files). That's the SHA-1 of the tree object attached to the commit:

$ git rev-parse HEAD^{tree}
61c3891747a3c82338ac995524e5d5958ec473b4
$ git rev-parse HEAD~3^{tree}
36812666a6ea99efc7455c7437a5e560f3803d46

To get the tree ID for the current index,1 write the index into the repository:2

$ git write-tree
61c3891747a3c82338ac995524e5d5958ec473b4

If this matches the tree ID of some existing commit, your work tree (not considering untracked files, of course) matches the tree in that commit.


1Thus, if your index does not match your work-tree, you'd need to git add and/or git rm --cached any files as appropriate.

2If you just want to compare to the HEAD tree, this is basically just a limited version of git status, with the side effect of writing a tree object into the repository that may simply have to be garbage collected later. So git status is generally the way to go instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top