Skip to content

Instantly share code, notes, and snippets.

@matthewstokeley
Created December 4, 2019 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewstokeley/c8312e6145e9bc77d7d1cdc0b70c22eb to your computer and use it in GitHub Desktop.
Save matthewstokeley/c8312e6145e9bc77d7d1cdc0b70c22eb to your computer and use it in GitHub Desktop.
git filter-branch notes

Summary
	- Rewrite git revision history
		- Applicable to `rev-list` branches
		- Only rewritepositive refs
		- Recommitted without any changes, unless filter is specified
		- Honors `.git/info/grafts` and refs in `refs/replace/`
		- Original refs written in `refs/original/`
		- An expensive disk writing option

Filters
	- Applied in order
	- Evaluated with `eval` 
	- Variables are piped from the current commit
		- Exported to the environment, prevents possible conflicts in rewriting commits.
- GIT_COMMIT
		- GIT_AUTHOR
		- GIT_AUTHOR_EMAIL
		- GIT_AUTHOR_DATE
		- GIT_COMMIR_NAME
		- GIT_COMMITTER_EMAIL
		- GIT_COMMITTER_DATE

- The hash is rewritten and noted as such. 

Options
—setup
	Not a real filter - applied before the loop - commit-specific variables have not been piped in yet. 


	Only applies to the history that touches the given subdirectory. 

—env-filter <command>
	Only modify the environment variables

—tree-filter <command>
	Rewrite the tree and its contents. 

—index-filter <command>
	Only rewrite the index - does not check out the tree (faster) - frequently used withgit rm —cached —ignore-unmatch …


	—parent-filter <command>
Only rewrite the commit’s parents. 

—msg-filter <command>
	Rewrite the commit message. 

—commit-filter <command>
	Performs the commit instead of git commit-tree

	—tag-name-filter
	Rewrites tag names

—prune-empty
	Removes empty commits (from revised commits that would leave an empty commit). 	Cannot be used with—commit-filter - instead, use the git_commit_non_empty_tree in a commit filter.

—original <namespace>
	Set the namespace. Defaults to refs/original. 

—d <directory>
	Defaults to .git-rewrite/

-f
Force filter-branch to use an existing temporary directory

—state-branch


<rev-list options>

	

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment