git's filter branch command

48
FILTER BRANCH Pruning And Separating Git Repository History

Upload: matthew-mccullough

Post on 07-Jan-2017

519 views

Category:

Technology


2 download

TRANSCRIPT

FILTER BRANCHPruning And Separating Git Repository History

The Command

Git Filter Branch

— Git Filter-Branch Man Page

Lets you rewrite git revision history by rewriting the branches mentioned in the <rev-list options>, applying custom filters on each revision.

Those filters can modify each tree (e.g. removing a file or running a perl rewrite on all files) or information about each commit.

Otherwise, all information (including original commit times or merge information) will be preserved.

Caution!This re-creates new/different hashes for all modified commits.

Caution!This is effectively a new repository that looks a lot like the old repository.

Modes

--env-filter

--tree-filter

--index-filter

--parent-filter

--msg-filter

--commit-filter

--tag-name-filter

--subdirectory-filter

Modes In Use

--env-filter

GIT_AUTHOR_NAMEGIT_AUTHOR_EMAILGIT_AUTHOR_DATEGIT_COMMITTER_NAMEGIT_COMMITTER_EMAILGIT_COMMITTER_DATE

git filter-branch --env-filter 'export GIT_AUTHOR_NAME=Bonzo'

--tree-filter

git filter-branch --tree-filter 'rm BADFILE' HEADgit filter-branch --tree-filter 'rm BADFILE' mastergit filter-branch --tree-filter 'rm BADFILE' otherbranchgit filter-branch --tree-filter 'find . -iname b -exec rm {} \;'

--index-filter

much faster for rm

git filter-branch --index-filter 'git rm --cached --ignore-unmatch FILENAME' HEAD

--parent-filter

Graft in a different parent

--msg-filter

git filter-branch --msg-filter ' sed -e "/^git-svn-id:/d"'

git filter-branch --msg-filter ' cat && echo "Signed-off-by Matthew McCullough"' HEAD~5..HEAD

--commit-filter

Remove certain commits based on commit contents

--tag-name-filter

Rename tags

--subdirectory-filter

git filter-branch --subdirectory-filter OLD -- --all

Options

--all

--prune-empty

--original

-d

--force

Closing and Q&A

github.com/training/free

FILTER BRANCHPruning And Separating Git Repository History