Package: hashbeaf
HashBeafYou don't like your git commit hashdc3fe60?
Or any of your others hashes?
With HashBeaf you can easily create hashes with words that you like in it, such asc0dec,abba:musical_note:,cafe:coffee: ordeadbeef:cow:.
The last one is probably too long to work, so let's trybeafas 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.ExampleSo you've made some changes to your git repository and staged some files.
Now, it is time to make a commit as normal:$gitcommit-m"Updated code"[mainb1c825b]Updatedcode12fileschanged,215insertions(+),2deletions(-)(...)But before you push, you think, meh,b1c825b, I can do better than that.
Now it is time to run HashBeaf:$hashbeafc0de[mainc0de2c4]UpdatedcodeDate:MonJun2620:43:072023+0200(...)And voila, we havec0de2c4, our HashBeaf'ed commit hash!Want to try it yourself?Install it with:pipinstallhashbeafThen navigate to your own git repository, make a commit, and then run either:hashbeafto use a default list of nice 'words', or something like this for a custom 'word':hashbeafc0deSeehashbeaf --helpfor more information.
There is also ahbalias if you don't want to type 8 characters.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.
Modifypost-committo point to the right absolute path (and customize it further as needed), and simple copy it toyour_repo/.git/hooks.
On the next commit hashbeaf should run automatically.Need some inspiration?
Check out thedefault words listfor nice commit hashes, or see more onWikipedia hereandhere.Implementation detailsThe algorithm is inspired bybeautify_git_hash, a slightly outdated tool that achieves the same thing.HashBeaf is implemented in Python and requires version 3.7 or newer.
It has been tested on Linux but might run on other operation systems.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)gitcommit--amend-CHEAD--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_futureis 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 developersInstead of installing the package throughpip, you can also run the script directly after checking out the repository as e.g.:python3-msrc.hashbeaf.hashbeafc0deFeature wish listMissing a feature?
Soon there will be also:More documentationMore error checking