Skip to main content

Git history rewriting tools - sanitise, flatten submodules, and remap references

Project description

git-rewrite

Git history rewriting tools - sanitise, flatten submodules, and remap references.

Installation

uv sync

Usage

Scan for Sensitive Words

Scan a repository for dirty words without making any changes:

uv run git-rewrite scan -r /path/to/repo -c config.json

Options:

  • -r, --repo - Path to the git repository
  • -c, --config - Path to JSON config file
  • -v, --verbose - Show verbose output

Sanitise Repository

Rewrite history to remove sensitive words:

uv run git-rewrite sanitise -r /path/to/repo -o /path/to/output -c config.json

Options:

  • -r, --repo - Path to source repository
  • -o, --output - Path for output repository
  • -c, --config - Path to JSON config file
  • -d, --default - Default replacement word (default: REDACTED)
  • -m, --commit-map - Path to write commit mapping file
  • -s, --submodule-map - Path to submodule commit mapping file
  • --delete - Delete output directory if exists
  • --sample-config - Print sample config and exit
  • -v, --verbose - Show verbose output

Sample Configuration

{
    "words": ["secretword", "internalname", "sensitiveid"],
    "word_mapping": {
        "secretword": "publicword",
        "internalname": "externalname"
    },
    "email_mapping": {
        "john smith": "jsmith@example.com",
        "jane doe": "jdoe@example.com"
    },
    "exclude_files": [
        "package-lock.json",
        "yarn.lock"
    ]
}

Flatten Submodules

Flatten submodules into the main repository:

# Scan for submodules only
uv run git-rewrite flatten -r /path/to/repo --scan-only

# Flatten submodules
uv run git-rewrite flatten -r /path/to/repo -o /path/to/output

Options:

  • -r, --repo - Path to source repository
  • -o, --output - Path for output repository
  • -m, --commit-map - Path to write commit mapping file
  • --scan-only - Only scan and list submodules
  • --delete - Delete output directory if exists
  • -v, --verbose - Show verbose output

Remap Submodule References

Update submodule commit references in a repository:

uv run git-rewrite remap -r /path/to/repo -o /path/to/output -m mapping.txt

Options:

  • -r, --repo - Path to source repository
  • -o, --output - Path for output repository
  • -m, --commit-map - Path to commit mapping file
  • --submodule-path - Specific submodule path to remap
  • --url-rewrite OLD NEW - Rewrite URL in .gitmodules (can repeat)
  • --delete - Delete output directory if exists
  • -v, --verbose - Show verbose output

Workflow Example

A typical workflow for cleaning up and flattening a repository:

# 1. Scan for sensitive words
uv run git-rewrite scan -r ./myrepo -c dirty-words.json

# 2. Sanitise the repository
uv run git-rewrite sanitise -r ./myrepo -o ./myrepo-clean -c dirty-words.json \
    -m commit-map.txt

# 3. Flatten submodules in the cleaned repo
uv run git-rewrite flatten -r ./myrepo-clean -o ./myrepo-flat -m submodule-map.txt

# 4. Update consumer repositories to use new submodule commits
uv run git-rewrite remap -r ./consumer-repo -o ./consumer-updated \
    -m submodule-map.txt --submodule-path libs/mylib

Development

# Install dependencies
make install

# Run linting and type checking
make check

# Auto-format code
make format

# Build wheel
make build

Requirements

  • Python 3.14+
  • Git

Licence

MIT

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

git_rewrite-0.3.0-py3-none-any.whl (39.4 kB view details)

Uploaded Python 3

File details

Details for the file git_rewrite-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: git_rewrite-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 39.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for git_rewrite-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b6e8d6512b32a4cd99264be9c361b75615c9d9fcf33f1ef325d64e1269515e17
MD5 725506889df6a43ae4d69efe43a872c6
BLAKE2b-256 73a0ed990a8b2722ca06600412974fff663f0ae74dc8e3e62541b50760256810

See more details on using hashes here.

Supported by

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