Get the current git hash in a Python script

No need to hack around getting data from the git command yourself. GitPython is a very nice way to do this and a lot of other git stuff. It even has “best effort” support for Windows. After pip install gitpython you can do import git repo = git.Repo(search_parent_directories=True) sha = repo.head.object.hexsha Something to consider when … Read more

How does Git compute file hashes?

Git prefixes the object with “blob “, followed by the length (as a human-readable integer), followed by a NUL character $ echo -e ‘blob 14\0Hello, World!’ | shasum 8ab686eafeb1f44702738c8b0f24f2567c36da6d Source: http://alblue.bandlem.com/2011/08/git-tip-of-week-objects.html

How to retrieve the hash for the current commit in Git?

To turn arbitrary extended object reference into SHA-1, use simply git-rev-parse, for example git rev-parse HEAD or git rev-parse –verify HEAD You can also retrieve the short version like this git rev-parse –short HEAD Sidenote: If you want to turn references (branches and tags) into SHA-1, there is git show-ref and git for-each-ref.