Skip to main content

hashcommit

A tool to generate a Git commit with a specific hash part.

Prerequisites

Ensure you have Git installed on your system.

Installation

You can install the package using pip:

pip install hashcommit

Demo

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.

Usage

Creating a New Commit

To create a new commit with a specific hash part:

hashcommit --hash <desired_hash_part> --message "<commit_message>"

Overwriting the Last Commit

To overwrite the last commit with a specific hash part:

hashcommit --hash <desired_hash_part> --message "<commit_message>" --overwrite

Match Type

You can also specify if the hash must begin with, contain, or end with the desired string using the --match-type option. Regex matching is also supported. The default is to match the beginning of the hash:

hashcommit --hash <desired_hash_part> --message "<commit_message>" --match-type <begin|contain|end|regex>

Example Usage

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 <your-email@domain.com>
Date:   Thu May 23 17:06:24 2024 +0000

    foobar

Author Preservation

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

Overwriting Commits in the Past

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>

Rewriting the History

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.

Development

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 .

Running Locally

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

License

This project is licensed under the MIT License.

Release files for hashcommit 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hashcommit 0.2.0
File Size Uploaded
hashcommit-0.2.0.tar.gz 10.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hashcommit 0.2.0
File Interpreter ABI Platform
hashcommit-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 20.0 kB

Release files / hashcommit-0.2.0.tar.gz

Download URL hashcommit-0.2.0.tar.gz
Size 10.6 kB
Tags Source
SHA-256 checksum
How to use checksums
0eb5126120d7762f99ace8fb95bf97299abb5854599db4df2ae24af7aef35de7
BLAKE2b-256 checksum
How to use checksums
444eb3f6477f26ac3799c01b812b05dd5d253c695807018702e6d7826bd832c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.7

Release files / hashcommit-0.2.0-py3-none-any.whl

Download URL hashcommit-0.2.0-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3f008a3592f52fb2fd8bf0d64bd93eb7320f10bc07bc168fd3c91c3524e63b7d
BLAKE2b-256 checksum
How to use checksums
465a03403d184ae767f03fb1af55070bcf11eb575d3db3b11cbae3b6890db2b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.7

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page