Skip to main content

A simple utility to create user-specified git commit hashes

Project description

HashBeaf

You don't like your git commit hash dc3fe60? Or any of your others hashes? With HashBeaf you can easily create hashes with words that you like in it, such as c0dec, abba :musical_note:, cafe :coffee: or deadbeef :cow:. The last one is probably too long to work, so let's try beaf as hash instead (now you understand the name - not a typo :wink:).

The way this works is that it computes a commit time based on your previous commit to get the right hash, so do use it with care.

Example

So you've made some changes to your git repository and staged some files. Now, it is time to make a commit as normal:

$ git commit -m "Updated code"
[main b1c825b] Updated code
 12 files changed, 215 insertions(+), 2 deletions(-)
(...)

But before you push, you think, meh, b1c825b, I can do better than that. Now it is time to run HashBeaf:

$ hashbeaf c0de
[main c0de2c4] Updated code
 Date: Mon Jun 26 20:43:07 2023 +0200
(...)

And voila, we have c0de2c4, our HashBeaf'ed commit hash!

Want to try it yourself?

Install it with pip install hashbeaf, navigate to your own git repository, make a commit, and then run either:

hashbeaf

to use a default list of nice 'words', or something like this for a custom 'word':

hashbeaf c0de

See hashbeaf --help for more information.

If you think it is too much work to run this after each commit, you can also install a git post-commit hook for your repository. Modify post-commit to point to the right absolute path (and customize it further as needed), and simple copy it to your_repo/.git/hooks. On the next commit hashbeaf should run automatically.

Need some inspiration? Check out the default words list for nice commit hashes, or see more on Wikipedia here and here.

Implementation details

The algorithm is inspired by beautify_git_hash, a slightly outdated tool that achieves the same thing.

HashBeaf is implemented in Python and requires version 3.7 or newer.

HashBeaf works as follows. A commit hash in git is computed based on the commit details, which include the commit message, author time and committer time. If we modify any of those, we get a new commit hash. With HashBeaf we set the author time and committer time to some time in the near future, compute a new hash, and if the hash starts with any of the user supplied 'words', we amend the previous commit by running something like:

GIT_COMMITTER_DATE=$(some_commit_time) git commit --amend -C HEAD --date=$(some_author_time)

HashBeaf keeps on changing the two times until either the given maximum time is reached or the nice hash is found. The algorithm tries to found times as close as possible to the actual commit/author times. For longer words (i.e. 5 characters or more) it is likely that the default maximum time is not enough: setting --max_minutes_in_future is recommended. However, be careful with increasing the time: it might confuse other users of your repository or can lead to incorrectly sorted commits in logs.

For developers

Instead of installing the package through pip, you can also run the script directly after checking out the repository as e.g.:

python3 -m src.hashbeaf.hashbeaf c0de

Feature wish list

Missing a feature? Soon there will be also:

  1. A pypi version that you can install as pip install hashbeaf.
  2. More tests
  3. More documentation
  4. More error checking

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hashbeaf-1.0.0.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

hashbeaf-1.0.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file hashbeaf-1.0.0.tar.gz.

File metadata

  • Download URL: hashbeaf-1.0.0.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for hashbeaf-1.0.0.tar.gz
Algorithm Hash digest
SHA256 680589c244c6fb15e0513eab1530feb9e1ff87e0cec693d420997a98e8655114
MD5 291e483ad7255b904dcad2a57e4a62b7
BLAKE2b-256 6453b233cdb7c1e2748855b428cdd18590e36c4f9689f94af1b1c19fdbad5af2

See more details on using hashes here.

File details

Details for the file hashbeaf-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: hashbeaf-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for hashbeaf-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b98088e80727bab48917a685e87fef3d1677c34eda16bae889e2a17a191401ed
MD5 3bea0f71d71257a38c6e7f92f22c0e86
BLAKE2b-256 c5b3f687f09ce56f0e37a14dcf0457c0b5735c7a838ecabd17a82ed5736b2609

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page