A tool to generate a Git commit with a specific hash part.
Ensure you have Git installed on your system.
You can install the package using pip:
pip install hashcommit
This repository's history was rewritten using the rewrite_the_history.sh
script and each new commit is added by using the hashcommit
command. You can check the result here.
To create a new commit with a specific hash part:
hashcommit --hash <desired_hash_part> --message "<commit_message>"
To overwrite the last commit with a specific hash part:
hashcommit --hash <desired_hash_part> --message "<commit_message>" --overwrite
You can also specify if the hash must begin with, contain, or end with the desired string using the --match-type
option. The default is to match the beginning of the hash:
hashcommit --hash <desired_hash_part> --message "<commit_message>" --match-type <begin|contain|end>
To find and use a specific commit hash:
hashcommit --hash fff --match-type contain --message "foobar" ; git log -1 | cat
Example output:
Found matching commit hash: 93fffe4756192c250a7234c7c5fd81752c747091
commit 93fffe4756192c250a7234c7c5fd81752c747091
Author: Your Name <[email protected]>
Date: Thu May 23 17:06:24 2024 +0000
foobar
By default, the author is preserved when overwriting. To overwrite the author, use the --no-preserve-author
option:
hashcommit --hash <desired_hash_part> --overwrite --no-preserve-author
You can overwrite the existing commit that has other commits on top of it. To do this, use the --commit
option:
hashcommit --hash <desired_hash_part> --overwrite --commit <commit_hash>
You can rewrite the history of the current branch using the rewrite_the_history.sh
script. This script will recreate the commit history, ensuring that each commit's hash conforms to a sequence specified by the -d
argument, which sets the number of digits for the sequence number.
For example, to rewrite the history with a two-digit sequence number at the beginning:
./scripts/rewrite_the_history.sh -d 2
Note: The default value for -d
is 3. As the number of commits increases, consider adjusting the digit value accordingly to balance performance and the required hash length.
To develop or contribute to this project, clone the repository and install the dependencies:
git clone https://github.com/wozniakpl/hashcommit.git
cd hashcommit
pip install -e .
You can run tests locally using tox or act:
# Using tox
tox
# Using act
act
You can use the following command for simplicity of development. It formats the code, runs the checks, and the tests on one Python version:
tox -e format && tox -e checks && tox -e py312 --
To run tox tests under docker (not using your git):
docker compose up
To set up an environment with hashcommit
installed and a git repository initialized in the /repo
directory, use Docker Compose:
docker compose run --rm --workdir /repo test bash
This project is licensed under the MIT License.