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
Then 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.
There is also a hb
alias 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.
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. 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) 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:
- More documentation
- More error checking
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file hashbeaf-1.1.1.tar.gz
.
File metadata
- Download URL: hashbeaf-1.1.1.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95ad631991b53c494ec22164022fbbe7bbb607a0c55c33dc67a221629b139fc8 |
|
MD5 | 5aa4fc4141fb7b1b71c182407683d9db |
|
BLAKE2b-256 | 40ec6b7494bc6c43fd7d97c4bbc45be6dffb43f4d2d79c698d0465b752167714 |
File details
Details for the file hashbeaf-1.1.1-py3-none-any.whl
.
File metadata
- Download URL: hashbeaf-1.1.1-py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c720c616a095a60ad9e30e9671ac38751db4e13071fe9f44c182515e5152dcef |
|
MD5 | 25bf66afdb48e58f3aff5de7f3544fbb |
|
BLAKE2b-256 | a51ca2f0bb9ef11fb018ca304d16078aba1b7e269e8af4939ad00380047e87b9 |