git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Document git-filter-branch

From
Frank Lichtenheld <frank@lichtenheld.de>
Date
Jul 3, 2007, 22:05 UTC
Message-ID
<20070703220540.GN12721@planck.djpig.de>
In-Reply-To
<Pine.LNX.4.64.0707031746400.4071@racer.site>

General note: All the stuff in all uppercase should probably also have some asciidoc emphasis.

On Tue, Jul 03, 2007 at 05:47:44PM +0100, Johannes Schindelin wrote:
Show 29 quoted lines
> +DESCRIPTION
> +-----------
> +Lets you rewrite git revision history by creating a new branch from
> +your current branch, 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.
> +
> +The command takes the new branch name as a mandatory argument and
> +the filters as optional arguments.  If you specify no filters, the
> +commits will be recommitted without any changes, which would normally
> +have no effect and result in the new branch pointing to the same
> +branch as your current branch.  Nevertheless, this may be useful in
> +the future for compensating for some git bugs or such, therefore
> +such a usage is permitted.
> +
> +WARNING! The rewritten history will have different object names for all
> +the objects and will not converge with the original branch.  You will not
> +be able to easily push and distribute the rewritten branch on top of the
> +original branch.  Please do not use this command if you do not know the
> +full implications, and avoid using it anyway, if a simple single commit
> +would suffice to fix your problem.
> +
> +Always verify that the rewritten version is correct before disposing
> +the original branch.
> +
> +Note that since this operation is extensively I/O expensive, it might
> +be a good idea to redirect the temporary directory it off-disk, e.g. on
                                                    ^^^^^^
The "it" probably doesn't belong there.
Show 9 quoted lines
> +tmpfs.  Reportedly the speedup is very noticeable.
> +
> +
> +Filters
> +~~~~~~~
> +
> +The filters are applied in the order as listed below.  The <command>
> +argument is always evaluated in shell using the 'eval' command.
> +The $GIT_COMMIT environment variable is permanently set to contain
                                           ^^^^^^^^^^^
I find the use of this word in this context odd and a little confusing.
Maybe better "always" or "each time"?
> +the id of the commit being rewritten.  The author/committer environment
> +variables are set before the first filter is run.
Maybe give the actual names of the environment variables here?
Show 23 quoted lines
> +A 'map' function is available that takes an "original sha1 id" argument
> +and outputs a "rewritten sha1 id" if the commit has been already
> +rewritten, fails otherwise; the 'map' function can return several
> +ids on separate lines if your commit filter emitted multiple commits.
> +
> +
> +OPTIONS
> +-------
> +
> +--env-filter <command>::
> +	This is the filter for modifying the environment in which
> +	the commit will be performed.  Specifically, you might want
> +	to rewrite the author/committer name/email/time environment
> +	variables (see gitlink:git-commit[1] for details).  Do not forget
> +	to re-export the variables.
> +
> +--tree-filter <command>::
> +	This is the filter for rewriting the tree and its contents.
> +	The argument is evaluated in shell with the working
> +	directory set to the root of the checked out tree.  The new tree
> +	is then used as-is (new files are auto-added, disappeared files
> +	are auto-removed - .gitignore files nor any other ignore rules
> +	HAVE NO EFFECT!).
Is "nor" correct here? Not just "or"?
[...]
> +--subdirectory-filter <directory>::
> +	Only regard the history, as seen by the given subdirectory. The
                              ^^^
Does this comma belong there?
Show 32 quoted lines
> +	result will contain that directory as its project root.
> +
> +-d <directory>::
> +	Use this option to set the path to the temporary directory used for
> +	rewriting.  When applying a tree filter, the command needs to
> +	temporary checkout the tree to some directory, which may consume
> +	considerable space in case of large projects.  By default it
> +	does this in the '.git-rewrite/' directory but you can override
> +	that choice by this parameter.
> +
> +<rev-list-options>::
> +	When options are given after the new branch name, they will
> +	be passed to gitlink:git-rev-list[1].  Only commits in the resulting
> +	output will be filtered, although the filtered commits can still
> +	reference parents which are outside of that set.
> +
> +
> +Examples
> +--------
> +
> +Suppose you want to remove a file (containing confidential information
> +or copyright violation) from all commits:
> +
> +-------------------------------------------------------
> +git filter-branch --tree-filter 'rm filename' newbranch
> +-------------------------------------------------------
> +
> +A significantly faster version:
> +
> +-------------------------------------------------------------------------------
> +git filter-branch --index-filter 'git update-index --remove filename' newbranch
> +-------------------------------------------------------------------------------

Even if your code goes beyond 80 chars, the surrounding "---" doesn't have to and makes it even harder to read when reading the original asciidoc text.

Show 10 quoted lines
> +
> +Now, you will get the rewritten history saved in the branch 'newbranch'
> +(your current branch is left untouched).
> +
> +To "etch-graft" a commit to the revision history (set a commit to be
> +the parent of the current initial commit and propagate that):
> +
> +----------------------------------------------------------------------
> +git filter-branch --parent-filter sed\ 's/^$/-p <graft-id>/' newbranch
> +----------------------------------------------------------------------

Wouldn't have 'sed s/^$/-p <graft-id>/' exactly the same effect, since the quotes are interpreted by the original shell anyway and not the filter shell? Just wondering why it uses such a complicated way to express it.

Show 5 quoted lines
> +(if the parent string is empty - therefore we are dealing with the
> +initial commit - add graftcommit as a parent).  Note that this assumes
> +history with a single root (that is, no merge without common ancestors
> +happened).  If this is not the case, use:
> +
[...]
Gruesse,
-- 
Frank Lichtenheld <frank@lichtenheld.de>
www: http://www.djpig.de/
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 2 of 12 in “Document git-filter-branch”
  1. Document git-filter-branchJohannes Schindelin, Jul 3, 2007
  2. Frank LichtenheldJul 3, 2007
  3. Johannes SchindelinJul 3, 2007
  4. Frank LichtenheldJul 4, 2007
  5. filter-branch: a few more touch ups to the man pageJohannes Schindelin, Jul 4, 2007
  6. Frank LichtenheldJul 4, 2007
  7. Jakub NarebskiJul 11, 2007
  8. Johannes SchindelinJul 11, 2007
  9. Document git-filter-branchJohannes Schindelin, Jul 3, 2007
  10. filter-branch documentation: some more touch-ups.Johannes Sixt, Jul 4, 2007
  11. Johannes SchindelinJul 4, 2007
  12. Junio C HamanoJul 4, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.