Git Trim is a deterministic tool to manipulate trees contained in git commits, and it is based on the excellent go-git library.
Often, the history and files contained in a git repository need to be filtered in some way.
One simple case will be a contributor is only allowed to access part of the repo.
This can be done through git-filter-branch
, although no so user-friendly.
gitrim
does just that:
- read git commit history.
- from start, filter the tree contained in the commit and copy over author, committor, commit message. The parents are replaced with the newly created commits, and GPG signatures are omitted.
As long as the filters don't change, the generated git history is deterministic and can be one-to-one mapped back to the original repo.
Modifications made in the trimmed/filtered repo can be recreated by
- filter the changes, and reject any changes that don't pass the filter.
- apply them back to the original repo, copying over author, committor, commit message, and add the original commits as parents. GPG signatures are again omitted.
The commits in the filtered/trimmed repo will match the commit reproduced from original repo if they are without GPG signatures.
The filter all implements the Filter interface
The pattern used is a more restricted version of the pattern used by .gitignore.
**
is for multi level directories, and it can only appear once in the match.*
is for match one level of names.!
and escapes are unsupported.- paths are always relative to the root (the leading
/
is implicit). For example,LICENSE
will only matchLICENSE
in the root of the repo. To matchLICENSE
at all directory levels, use**/LICENSE
.
Refer to documentation on PatternFilter
gitrim
, through go-git, operates on the contents of .git
(or dotgit) folder (the commit,
blob, and tree objects).
See Examples
- filter-git-hist filters the history of a git repo and output it to another git repo.
- expand-git-commit expands the new commit back to the original repo.
- dump-git-tree prints the files of a branch/tree/commit/head. Optionally filters can be applied.
- remve-git-gpg removes gpg signatures for commits.