Overview
The git-filter-repo library represents Git objects as Python classes. These objects are created when parsing fast-export output and can be modified by your callbacks before being written to fast-import.Blob
Represents file content (a Git blob object).The file content as bytes
The original Git hash of the blob (from fast-export’s
original-oid)Attributes
The mark (internal ID) for this blob in the fast-import stream
The original mark from fast-export, if different from
idThe Git object hash (40-character hex string)
The blob content. Modify this to change file contents.
Whether this object has been written (0=not yet, 1=written, 2=skipped)
Methods
Writes the blob to the fast-import stream
Marks this blob to be skipped (not written to output)
Example
FileChange
Represents a file change within a commit (modify, delete, or rename).The type of change:
b'M' (modify), b'D' (delete), or b'DELETEALL'The file path (required for M and D, None for DELETEALL)
The blob ID (mark or hash). Required for M type.
File mode:
b'100644' (regular), b'100755' (executable), b'120000' (symlink), or b'160000' (submodule)Attributes
The change type (
b'M', b'D', or b'DELETEALL')The file path relative to repository root
The file mode (Unix permissions)
The blob mark or hash. None means the blob was filtered out.
Example
Commit
Represents a Git commit with all its metadata and file changes.The branch name (e.g.,
b'refs/heads/main')Author’s name
Author’s email
Author date in format:
b'1234567890 +0000'Committer’s name
Committer’s email
Committer date in format:
b'1234567890 +0000'The commit message
List of FileChange objects
List of parent commit IDs (marks or hashes)
Original Git commit hash
Commit message encoding (None implies UTF-8)
Attributes
All constructor parameters are available as attributes, plus:The mark for this commit
The original mark from fast-export
Methods
Returns the first parent commit ID, or None if no parents
Marks this commit to be skipped (not written). If parents exist, commits that had this as a parent will use
new_id as the new parent.Example
Tag
Represents an annotated tag.Tag name (without
refs/tags/ prefix)The commit this tag points to (mark or hash)
Tagger’s name
Tagger’s email
Tag date in format:
b'1234567890 +0000'The tag message
Original Git tag hash
Example
Reset
Represents a branch creation or reset.The branch reference (e.g.,
b'refs/heads/main')The commit to reset/point the branch to (mark or hash)
Example
Progress
Represents a progress message that fast-import can display.The progress message
Checkpoint
Represents a checkpoint directive for fast-import (forces writing current state).Date Utilities
Helper functions for working with Git date formats.string_to_date
Parse a Git date string into a Python datetime object.Git date format:
b'<unix_timestamp> <timezone_offset>'datetime object with timezone information.
date_to_string
Convert a datetime object to Git date format.A datetime object with timezone information
b'<unix_timestamp> <timezone_offset>'
