{
    "content": [
        {
            "type": "text",
            "text": "# GIT-FILTER-BRANCH (man)\n\n## NAME\n\ngit-filter-branch - Rewrite branches\n\n## SYNOPSIS\n\ngit filter-branch [--setup <command>] [--subdirectory-filter <directory>]\n[--env-filter <command>] [--tree-filter <command>]\n[--index-filter <command>] [--parent-filter <command>]\n[--msg-filter <command>] [--commit-filter <command>]\n[--tag-name-filter <command>] [--prune-empty]\n[--original <namespace>] [-d <directory>] [-f | --force]\n[--state-branch <branch>] [--] [<rev-list options>...]\n\n## DESCRIPTION\n\nLets you rewrite Git revision history by rewriting the branches mentioned in the <rev-list\noptions>, applying custom filters on each revision. Those filters can modify each tree (e.g.\nremoving a file or running a perl rewrite on all files) or information about each commit.\nOtherwise, all information (including original commit times or merge information) will be\npreserved.\n\n## TLDR\n\n> Change branch history, like removing files.\n\n- Remove a file from all commits:\n  `git filter-branch --tree-filter 'rm {{-f|--force}} {{file}}' HEAD`\n- Update author email:\n  `git filter-branch --env-filter 'GIT_AUTHOR_EMAIL={{new_email}}' HEAD`\n- Delete a folder from history:\n  `git filter-branch --tree-filter 'rm {{-rf|--recursive --force}} {{folder}}' HEAD`\n\n*Source: tldr-pages*\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **WARNING**\n- **DESCRIPTION** (1 subsections)\n- **OPTIONS** (15 subsections)\n- **EXIT STATUS**\n- **EXAMPLES**\n- **CHECKLIST FOR SHRINKING A REPOSITORY**\n- **PERFORMANCE**\n- **SAFETY**\n- **GIT**\n- **NOTES**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "GIT-FILTER-BRANCH",
        "section": "",
        "mode": "man",
        "summary": "git-filter-branch - Rewrite branches",
        "synopsis": "git filter-branch [--setup <command>] [--subdirectory-filter <directory>]\n[--env-filter <command>] [--tree-filter <command>]\n[--index-filter <command>] [--parent-filter <command>]\n[--msg-filter <command>] [--commit-filter <command>]\n[--tag-name-filter <command>] [--prune-empty]\n[--original <namespace>] [-d <directory>] [-f | --force]\n[--state-branch <branch>] [--] [<rev-list options>...]",
        "tldr_summary": "Change branch history, like removing files.",
        "tldr_examples": [
            {
                "description": "Remove a file from all commits",
                "command": "git filter-branch --tree-filter 'rm {{-f|--force}} {{file}}' HEAD"
            },
            {
                "description": "Update author email",
                "command": "git filter-branch --env-filter 'GIT_AUTHOR_EMAIL={{new_email}}' HEAD"
            },
            {
                "description": "Delete a folder from history",
                "command": "git filter-branch --tree-filter 'rm {{-rf|--recursive --force}} {{folder}}' HEAD"
            }
        ],
        "tldr_source": "official",
        "flags": [
            {
                "flag": "",
                "long": "--setup",
                "arg": "<command>",
                "description": "This is not a real filter executed for each commit but a one time setup just before the loop. Therefore no commit-specific variables are defined yet. Functions or variables defined here can be used or modified in the following filter steps except the commit filter, for technical reasons."
            },
            {
                "flag": "",
                "long": "--subdirectory-filter",
                "arg": "<directory>",
                "description": "Only look at the history which touches the given subdirectory. The result will contain that directory (and only that) as its project root. Implies the section called “Remap to ancestor”."
            },
            {
                "flag": "",
                "long": "--env-filter",
                "arg": "<command>",
                "description": "This filter may be used if you only need to modify the environment in which the commit will be performed. Specifically, you might want to rewrite the author/committer name/email/time environment variables (see git-commit-tree(1) for details)."
            },
            {
                "flag": "",
                "long": "--tree-filter",
                "arg": "<command>",
                "description": "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 - neither .gitignore files nor any other ignore rules HAVE ANY EFFECT!)."
            },
            {
                "flag": "",
                "long": "--index-filter",
                "arg": "<command>",
                "description": "This is the filter for rewriting the index. It is similar to the tree filter but does not check out the tree, which makes it much faster. Frequently used with git rm --cached --ignore-unmatch ..., see EXAMPLES below. For hairy cases, see git-update-index(1)."
            },
            {
                "flag": "",
                "long": "--parent-filter",
                "arg": "<command>",
                "description": "This is the filter for rewriting the commit’s parent list. It will receive the parent string on stdin and shall output the new parent string on stdout. The parent string is in the format described in git-commit-tree(1): empty for the initial commit, \"-p parent\" for a normal commit and \"-p parent1 -p parent2 -p parent3 ...\" for a merge commit."
            },
            {
                "flag": "",
                "long": "--msg-filter",
                "arg": "<command>",
                "description": "This is the filter for rewriting the commit messages. The argument is evaluated in the shell with the original commit message on standard input; its standard output is used as the new commit message."
            },
            {
                "flag": "",
                "long": "--commit-filter",
                "arg": "<command>",
                "description": "This is the filter for performing the commit. If this filter is specified, it will be called instead of the git commit-tree command, with arguments of the form \"<TREEID> [(-p <PARENTCOMMITID>)...]\" and the log message on stdin. The commit id is expected on stdout. As a special extension, the commit filter may emit multiple commit ids; in that case, the rewritten children of the original commit will have all of them as parents. You can use the map convenience function in this filter, and other convenience functions, too. For example, calling skipcommit \"$@\" will leave out the current commit (but not its changes! If you want that, use git rebase instead). You can also use the gitcommitnonemptytree \"$@\" instead of git commit-tree \"$@\" if you don’t wish to keep commits with a single parent and that makes no change to the tree."
            },
            {
                "flag": "",
                "long": "--tag-name-filter",
                "arg": "<command>",
                "description": "This is the filter for rewriting tag names. When passed, it will be called for every tag ref that points to a rewritten object (or to a tag object which points to a rewritten object). The original tag name is passed via standard input, and the new tag name is expected on standard output. The original tags are not deleted, but can be overwritten; use \"--tag-name-filter cat\" to simply update the tags. In this case, be very careful and make sure you have the old tags backed up in case the conversion has run afoul. Nearly proper rewriting of tag objects is supported. If the tag has a message attached, a new tag object will be created with the same message, author, and timestamp. If the tag has a signature attached, the signature will be stripped. It is by definition impossible to preserve signatures. The reason this is \"nearly\" proper, is because ideally if the tag did not change (points to the same object, has the same name, etc.) it should retain any signature. That is not the case, signatures will always be removed, buyer beware. There is also no support for changing the author or timestamp (or the tag message for that matter). Tags which point to other tags will be rewritten to point to the underlying commit."
            },
            {
                "flag": "",
                "long": "--prune-empty",
                "arg": null,
                "description": "Some filters will generate empty commits that leave the tree untouched. This option instructs git-filter-branch to remove such commits if they have exactly one or zero non-pruned parents; merge commits will therefore remain intact. This option cannot be used together with --commit-filter, though the same effect can be achieved by using the provided gitcommitnonemptytree function in a commit filter."
            },
            {
                "flag": "",
                "long": "--original",
                "arg": "<namespace>",
                "description": "Use this option to set the namespace where the original commits will be stored. The default value is refs/original."
            },
            {
                "flag": "-d",
                "long": null,
                "arg": "<directory>",
                "description": "Use this option to set the path to the temporary directory used for rewriting. When applying a tree filter, the command needs to temporarily check out 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."
            },
            {
                "flag": "-f",
                "long": "--force",
                "arg": null,
                "description": "git filter-branch refuses to start with an existing temporary directory or when there are already refs starting with refs/original/, unless forced."
            },
            {
                "flag": "",
                "long": "--state-branch",
                "arg": "<branch>",
                "description": "This option will cause the mapping from old to new objects to be loaded from named branch upon startup and saved as a new commit to that branch upon exit, enabling incremental of large trees. If <branch> does not exist it will be created. <rev-list options>... Arguments for git rev-list. All positive refs included by these options are rewritten. You may also specify options such as --all, but you must use -- to separate them from the git filter-branch options. Implies the section called “Remap to ancestor”."
            }
        ],
        "examples": [
            "Suppose you want to remove a file (containing confidential information or copyright",
            "violation) from all commits:",
            "git filter-branch --tree-filter 'rm filename' HEAD",
            "However, if the file is absent from the tree of some commit, a simple rm filename will fail",
            "for that tree and commit. Thus you may instead want to use rm -f filename as the script.",
            "Using --index-filter with git rm yields a significantly faster version. Like with using rm",
            "filename, git rm --cached filename will fail if the file is absent from the tree of a commit.",
            "If you want to \"completely forget\" a file, it does not matter when it entered history, so we",
            "also add --ignore-unmatch:",
            "git filter-branch --index-filter 'git rm --cached --ignore-unmatch filename' HEAD",
            "Now, you will get the rewritten history saved in HEAD.",
            "To rewrite the repository to look as if foodir/ had been its project root, and discard all",
            "other history:",
            "git filter-branch --subdirectory-filter foodir -- --all",
            "Thus you can, e.g., turn a library subdirectory into a repository of its own. Note the --",
            "that separates filter-branch options from revision options, and the --all to rewrite all",
            "branches and tags.",
            "To set a commit (which typically is at the tip of another history) to be the parent of the",
            "current initial commit, in order to paste the other history behind the current history:",
            "git filter-branch --parent-filter 'sed \"s/^\\$/-p <graft-id>/\"' HEAD",
            "(if the parent string is empty - which happens when 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:",
            "git filter-branch --parent-filter \\",
            "'test $GITCOMMIT = <commit-id> && echo \"-p <graft-id>\" || cat' HEAD",
            "or even simpler:",
            "git replace --graft $commit-id $graft-id",
            "git filter-branch $graft-id..HEAD",
            "To remove commits authored by \"Darl McBribe\" from the history:",
            "git filter-branch --commit-filter '",
            "if [ \"$GITAUTHORNAME\" = \"Darl McBribe\" ];",
            "then",
            "skipcommit \"$@\";",
            "else",
            "git commit-tree \"$@\";",
            "fi' HEAD",
            "The function skipcommit is defined as follows:",
            "skipcommit()",
            "shift;",
            "while [ -n \"$1\" ];",
            "do",
            "shift;",
            "map \"$1\";",
            "shift;",
            "done;",
            "The shift magic first throws away the tree id and then the -p parameters. Note that this",
            "handles merges properly! In case Darl committed a merge between P1 and P2, it will be",
            "propagated properly and all children of the merge will become merge commits with P1,P2 as",
            "their parents instead of the merge commit.",
            "NOTE the changes introduced by the commits, and which are not reverted by subsequent commits,",
            "will still be in the rewritten branch. If you want to throw out changes together with the",
            "commits, you should use the interactive mode of git rebase.",
            "You can rewrite the commit log messages using --msg-filter. For example, git svn-id strings",
            "in a repository created by git svn can be removed this way:",
            "git filter-branch --msg-filter '",
            "sed -e \"/^git-svn-id:/d\"",
            "If you need to add Acked-by lines to, say, the last 10 commits (none of which is a merge),",
            "use this command:",
            "git filter-branch --msg-filter '",
            "cat &&",
            "echo \"Acked-by: Bugs Bunny <bunny@bugzilla.org>\"",
            "' HEAD~10..HEAD",
            "The --env-filter option can be used to modify committer and/or author identity. For example,",
            "if you found out that your commits have the wrong identity due to a misconfigured user.email,",
            "you can make a correction, before publishing the project, like this:",
            "git filter-branch --env-filter '",
            "if test \"$GITAUTHOREMAIL\" = \"root@localhost\"",
            "then",
            "GITAUTHOREMAIL=john@example.com",
            "fi",
            "if test \"$GITCOMMITTEREMAIL\" = \"root@localhost\"",
            "then",
            "GITCOMMITTEREMAIL=john@example.com",
            "fi",
            "' -- --all",
            "To restrict rewriting to only part of the history, specify a revision range in addition to",
            "the new branch name. The new branch name will point to the top-most revision that a git",
            "rev-list of this range will print.",
            "Consider this history:",
            "D--E--F--G--H",
            "/     /",
            "A--B-----C",
            "To rewrite only commits D,E,F,G,H, but leave A, B and C alone, use:",
            "git filter-branch ... C..H",
            "To rewrite commits E,F,G,H, use one of these:",
            "git filter-branch ... C..H --not D",
            "git filter-branch ... D..H --not C",
            "To move the whole tree into a subdirectory, or remove it from there:",
            "git filter-branch --index-filter \\",
            "'git ls-files -s | sed \"s-\\t\\\"*-&newsubdir/-\" |",
            "GITINDEXFILE=$GITINDEXFILE.new \\",
            "git update-index --index-info &&",
            "mv \"$GITINDEXFILE.new\" \"$GITINDEXFILE\"' HEAD"
        ],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 9,
                "subsections": []
            },
            {
                "name": "WARNING",
                "lines": 9,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 30,
                "subsections": [
                    {
                        "name": "Filters",
                        "lines": 17
                    }
                ]
            },
            {
                "name": "OPTIONS",
                "lines": 1,
                "subsections": [
                    {
                        "name": "--setup <command>",
                        "lines": 5,
                        "long": "--setup",
                        "arg": "<command>"
                    },
                    {
                        "name": "--subdirectory-filter <directory>",
                        "lines": 4,
                        "long": "--subdirectory-filter",
                        "arg": "<directory>"
                    },
                    {
                        "name": "--env-filter <command>",
                        "lines": 4,
                        "long": "--env-filter",
                        "arg": "<command>"
                    },
                    {
                        "name": "--tree-filter <command>",
                        "lines": 5,
                        "long": "--tree-filter",
                        "arg": "<command>"
                    },
                    {
                        "name": "--index-filter <command>",
                        "lines": 4,
                        "long": "--index-filter",
                        "arg": "<command>"
                    },
                    {
                        "name": "--parent-filter <command>",
                        "lines": 5,
                        "long": "--parent-filter",
                        "arg": "<command>"
                    },
                    {
                        "name": "--msg-filter <command>",
                        "lines": 4,
                        "long": "--msg-filter",
                        "arg": "<command>"
                    },
                    {
                        "name": "--commit-filter <command>",
                        "lines": 15,
                        "long": "--commit-filter",
                        "arg": "<command>"
                    },
                    {
                        "name": "--tag-name-filter <command>",
                        "lines": 19,
                        "long": "--tag-name-filter",
                        "arg": "<command>"
                    },
                    {
                        "name": "--prune-empty",
                        "lines": 6,
                        "long": "--prune-empty"
                    },
                    {
                        "name": "--original <namespace>",
                        "lines": 3,
                        "long": "--original",
                        "arg": "<namespace>"
                    },
                    {
                        "name": "-d <directory>",
                        "lines": 6,
                        "flag": "-d",
                        "arg": "<directory>"
                    },
                    {
                        "name": "-f, --force",
                        "lines": 3,
                        "flag": "-f",
                        "long": "--force"
                    },
                    {
                        "name": "--state-branch <branch>",
                        "lines": 9,
                        "long": "--state-branch",
                        "arg": "<branch>"
                    },
                    {
                        "name": "Remap to ancestor",
                        "lines": 5
                    }
                ]
            },
            {
                "name": "EXIT STATUS",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "EXAMPLES",
                "lines": 147,
                "subsections": []
            },
            {
                "name": "CHECKLIST FOR SHRINKING A REPOSITORY",
                "lines": 30,
                "subsections": []
            },
            {
                "name": "PERFORMANCE",
                "lines": 61,
                "subsections": []
            },
            {
                "name": "SAFETY",
                "lines": 127,
                "subsections": []
            },
            {
                "name": "GIT",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "NOTES",
                "lines": 9,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "git-filter-branch - Rewrite branches\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "git filter-branch [--setup <command>] [--subdirectory-filter <directory>]\n[--env-filter <command>] [--tree-filter <command>]\n[--index-filter <command>] [--parent-filter <command>]\n[--msg-filter <command>] [--commit-filter <command>]\n[--tag-name-filter <command>] [--prune-empty]\n[--original <namespace>] [-d <directory>] [-f | --force]\n[--state-branch <branch>] [--] [<rev-list options>...]\n\n",
                "subsections": []
            },
            "WARNING": {
                "content": "git filter-branch has a plethora of pitfalls that can produce non-obvious manglings of the\nintended history rewrite (and can leave you with little time to investigate such problems\nsince it has such abysmal performance). These safety and performance issues cannot be\nbackward compatibly fixed and as such, its use is not recommended. Please use an alternative\nhistory filtering tool such as git filter-repo[1]. If you still need to use git\nfilter-branch, please carefully read the section called “SAFETY” (and the section called\n“PERFORMANCE”) to learn about the land mines of filter-branch, and then vigilantly avoid as\nmany of the hazards listed there as reasonably possible.\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "Lets you rewrite Git revision history by rewriting the branches mentioned in the <rev-list\noptions>, applying custom filters on each revision. Those filters can modify each tree (e.g.\nremoving a file or running a perl rewrite on all files) or information about each commit.\nOtherwise, all information (including original commit times or merge information) will be\npreserved.\n\nThe command will only rewrite the positive refs mentioned in the command line (e.g. if you\npass a..b, only b will be rewritten). If you specify no filters, the commits will be\nrecommitted without any changes, which would normally have no effect. Nevertheless, this may\nbe useful in the future for compensating for some Git bugs or such, therefore such a usage is\npermitted.\n\nNOTE: This command honors .git/info/grafts file and refs in the refs/replace/ namespace. If\nyou have any grafts or replacement refs defined, running this command will make them\npermanent.\n\nWARNING! The rewritten history will have different object names for all the objects and will\nnot converge with the original branch. You will not be able to easily push and distribute the\nrewritten branch on top of the original branch. Please do not use this command if you do not\nknow the full implications, and avoid using it anyway, if a simple single commit would\nsuffice to fix your problem. (See the \"RECOVERING FROM UPSTREAM REBASE\" section in git-\nrebase(1) for further information about rewriting published history.)\n\nAlways verify that the rewritten version is correct: The original refs, if different from the\nrewritten ones, will be stored in the namespace refs/original/.\n\nNote that since this operation is very I/O expensive, it might be a good idea to redirect the\ntemporary directory off-disk with the -d option, e.g. on tmpfs. Reportedly the speedup is\nvery noticeable.\n",
                "subsections": [
                    {
                        "name": "Filters",
                        "content": "The filters are applied in the order as listed below. The <command> argument is always\nevaluated in the shell context using the eval command (with the notable exception of the\ncommit filter, for technical reasons). Prior to that, the $GITCOMMIT environment variable\nwill be set to contain the id of the commit being rewritten. Also, GITAUTHORNAME,\nGITAUTHOREMAIL, GITAUTHORDATE, GITCOMMITTERNAME, GITCOMMITTEREMAIL, and\nGITCOMMITTERDATE are taken from the current commit and exported to the environment, in\norder to affect the author and committer identities of the replacement commit created by git-\ncommit-tree(1) after the filters have run.\n\nIf any evaluation of <command> returns a non-zero exit status, the whole operation will be\naborted.\n\nA map function is available that takes an \"original sha1 id\" argument and outputs a\n\"rewritten sha1 id\" if the commit has been already rewritten, and \"original sha1 id\"\notherwise; the map function can return several ids on separate lines if your commit filter\nemitted multiple commits.\n"
                    }
                ]
            },
            "OPTIONS": {
                "content": "",
                "subsections": [
                    {
                        "name": "--setup <command>",
                        "content": "This is not a real filter executed for each commit but a one time setup just before the\nloop. Therefore no commit-specific variables are defined yet. Functions or variables\ndefined here can be used or modified in the following filter steps except the commit\nfilter, for technical reasons.\n",
                        "long": "--setup",
                        "arg": "<command>"
                    },
                    {
                        "name": "--subdirectory-filter <directory>",
                        "content": "Only look at the history which touches the given subdirectory. The result will contain\nthat directory (and only that) as its project root. Implies the section called “Remap to\nancestor”.\n",
                        "long": "--subdirectory-filter",
                        "arg": "<directory>"
                    },
                    {
                        "name": "--env-filter <command>",
                        "content": "This filter may be used if you only need to modify the environment in which the commit\nwill be performed. Specifically, you might want to rewrite the author/committer\nname/email/time environment variables (see git-commit-tree(1) for details).\n",
                        "long": "--env-filter",
                        "arg": "<command>"
                    },
                    {
                        "name": "--tree-filter <command>",
                        "content": "This is the filter for rewriting the tree and its contents. The argument is evaluated in\nshell with the working directory set to the root of the checked out tree. The new tree is\nthen used as-is (new files are auto-added, disappeared files are auto-removed - neither\n.gitignore files nor any other ignore rules HAVE ANY EFFECT!).\n",
                        "long": "--tree-filter",
                        "arg": "<command>"
                    },
                    {
                        "name": "--index-filter <command>",
                        "content": "This is the filter for rewriting the index. It is similar to the tree filter but does not\ncheck out the tree, which makes it much faster. Frequently used with git rm --cached\n--ignore-unmatch ..., see EXAMPLES below. For hairy cases, see git-update-index(1).\n",
                        "long": "--index-filter",
                        "arg": "<command>"
                    },
                    {
                        "name": "--parent-filter <command>",
                        "content": "This is the filter for rewriting the commit’s parent list. It will receive the parent\nstring on stdin and shall output the new parent string on stdout. The parent string is in\nthe format described in git-commit-tree(1): empty for the initial commit, \"-p parent\" for\na normal commit and \"-p parent1 -p parent2 -p parent3 ...\" for a merge commit.\n",
                        "long": "--parent-filter",
                        "arg": "<command>"
                    },
                    {
                        "name": "--msg-filter <command>",
                        "content": "This is the filter for rewriting the commit messages. The argument is evaluated in the\nshell with the original commit message on standard input; its standard output is used as\nthe new commit message.\n",
                        "long": "--msg-filter",
                        "arg": "<command>"
                    },
                    {
                        "name": "--commit-filter <command>",
                        "content": "This is the filter for performing the commit. If this filter is specified, it will be\ncalled instead of the git commit-tree command, with arguments of the form \"<TREEID> [(-p\n<PARENTCOMMITID>)...]\" and the log message on stdin. The commit id is expected on\nstdout.\n\nAs a special extension, the commit filter may emit multiple commit ids; in that case, the\nrewritten children of the original commit will have all of them as parents.\n\nYou can use the map convenience function in this filter, and other convenience functions,\ntoo. For example, calling skipcommit \"$@\" will leave out the current commit (but not its\nchanges! If you want that, use git rebase instead).\n\nYou can also use the gitcommitnonemptytree \"$@\" instead of git commit-tree \"$@\" if\nyou don’t wish to keep commits with a single parent and that makes no change to the tree.\n",
                        "long": "--commit-filter",
                        "arg": "<command>"
                    },
                    {
                        "name": "--tag-name-filter <command>",
                        "content": "This is the filter for rewriting tag names. When passed, it will be called for every tag\nref that points to a rewritten object (or to a tag object which points to a rewritten\nobject). The original tag name is passed via standard input, and the new tag name is\nexpected on standard output.\n\nThe original tags are not deleted, but can be overwritten; use \"--tag-name-filter cat\" to\nsimply update the tags. In this case, be very careful and make sure you have the old tags\nbacked up in case the conversion has run afoul.\n\nNearly proper rewriting of tag objects is supported. If the tag has a message attached, a\nnew tag object will be created with the same message, author, and timestamp. If the tag\nhas a signature attached, the signature will be stripped. It is by definition impossible\nto preserve signatures. The reason this is \"nearly\" proper, is because ideally if the tag\ndid not change (points to the same object, has the same name, etc.) it should retain any\nsignature. That is not the case, signatures will always be removed, buyer beware. There\nis also no support for changing the author or timestamp (or the tag message for that\nmatter). Tags which point to other tags will be rewritten to point to the underlying\ncommit.\n",
                        "long": "--tag-name-filter",
                        "arg": "<command>"
                    },
                    {
                        "name": "--prune-empty",
                        "content": "Some filters will generate empty commits that leave the tree untouched. This option\ninstructs git-filter-branch to remove such commits if they have exactly one or zero\nnon-pruned parents; merge commits will therefore remain intact. This option cannot be\nused together with --commit-filter, though the same effect can be achieved by using the\nprovided gitcommitnonemptytree function in a commit filter.\n",
                        "long": "--prune-empty"
                    },
                    {
                        "name": "--original <namespace>",
                        "content": "Use this option to set the namespace where the original commits will be stored. The\ndefault value is refs/original.\n",
                        "long": "--original",
                        "arg": "<namespace>"
                    },
                    {
                        "name": "-d <directory>",
                        "content": "Use this option to set the path to the temporary directory used for rewriting. When\napplying a tree filter, the command needs to temporarily check out the tree to some\ndirectory, which may consume considerable space in case of large projects. By default it\ndoes this in the .git-rewrite/ directory but you can override that choice by this\nparameter.\n",
                        "flag": "-d",
                        "arg": "<directory>"
                    },
                    {
                        "name": "-f, --force",
                        "content": "git filter-branch refuses to start with an existing temporary directory or when there are\nalready refs starting with refs/original/, unless forced.\n",
                        "flag": "-f",
                        "long": "--force"
                    },
                    {
                        "name": "--state-branch <branch>",
                        "content": "This option will cause the mapping from old to new objects to be loaded from named branch\nupon startup and saved as a new commit to that branch upon exit, enabling incremental of\nlarge trees. If <branch> does not exist it will be created.\n\n<rev-list options>...\nArguments for git rev-list. All positive refs included by these options are rewritten.\nYou may also specify options such as --all, but you must use -- to separate them from the\ngit filter-branch options. Implies the section called “Remap to ancestor”.\n",
                        "long": "--state-branch",
                        "arg": "<branch>"
                    },
                    {
                        "name": "Remap to ancestor",
                        "content": "By using git-rev-list(1) arguments, e.g., path limiters, you can limit the set of revisions\nwhich get rewritten. However, positive refs on the command line are distinguished: we don’t\nlet them be excluded by such limiters. For this purpose, they are instead rewritten to point\nat the nearest ancestor that was not excluded.\n"
                    }
                ]
            },
            "EXIT STATUS": {
                "content": "On success, the exit status is 0. If the filter can’t find any commits to rewrite, the exit\nstatus is 2. On any other error, the exit status may be any other non-zero value.\n",
                "subsections": []
            },
            "EXAMPLES": {
                "content": "Suppose you want to remove a file (containing confidential information or copyright\nviolation) from all commits:\n\ngit filter-branch --tree-filter 'rm filename' HEAD\n\n\nHowever, if the file is absent from the tree of some commit, a simple rm filename will fail\nfor that tree and commit. Thus you may instead want to use rm -f filename as the script.\n\nUsing --index-filter with git rm yields a significantly faster version. Like with using rm\nfilename, git rm --cached filename will fail if the file is absent from the tree of a commit.\nIf you want to \"completely forget\" a file, it does not matter when it entered history, so we\nalso add --ignore-unmatch:\n\ngit filter-branch --index-filter 'git rm --cached --ignore-unmatch filename' HEAD\n\n\nNow, you will get the rewritten history saved in HEAD.\n\nTo rewrite the repository to look as if foodir/ had been its project root, and discard all\nother history:\n\ngit filter-branch --subdirectory-filter foodir -- --all\n\n\nThus you can, e.g., turn a library subdirectory into a repository of its own. Note the --\nthat separates filter-branch options from revision options, and the --all to rewrite all\nbranches and tags.\n\nTo set a commit (which typically is at the tip of another history) to be the parent of the\ncurrent initial commit, in order to paste the other history behind the current history:\n\ngit filter-branch --parent-filter 'sed \"s/^\\$/-p <graft-id>/\"' HEAD\n\n\n(if the parent string is empty - which happens when we are dealing with the initial commit -\nadd graftcommit as a parent). Note that this assumes history with a single root (that is, no\nmerge without common ancestors happened). If this is not the case, use:\n\ngit filter-branch --parent-filter \\\n'test $GITCOMMIT = <commit-id> && echo \"-p <graft-id>\" || cat' HEAD\n\n\nor even simpler:\n\ngit replace --graft $commit-id $graft-id\ngit filter-branch $graft-id..HEAD\n\n\nTo remove commits authored by \"Darl McBribe\" from the history:\n\ngit filter-branch --commit-filter '\nif [ \"$GITAUTHORNAME\" = \"Darl McBribe\" ];\nthen\nskipcommit \"$@\";\nelse\ngit commit-tree \"$@\";\nfi' HEAD\n\n\nThe function skipcommit is defined as follows:\n\nskipcommit()\n{\nshift;\nwhile [ -n \"$1\" ];\ndo\nshift;\nmap \"$1\";\nshift;\ndone;\n}\n\n\nThe shift magic first throws away the tree id and then the -p parameters. Note that this\nhandles merges properly! In case Darl committed a merge between P1 and P2, it will be\npropagated properly and all children of the merge will become merge commits with P1,P2 as\ntheir parents instead of the merge commit.\n\nNOTE the changes introduced by the commits, and which are not reverted by subsequent commits,\nwill still be in the rewritten branch. If you want to throw out changes together with the\ncommits, you should use the interactive mode of git rebase.\n\nYou can rewrite the commit log messages using --msg-filter. For example, git svn-id strings\nin a repository created by git svn can be removed this way:\n\ngit filter-branch --msg-filter '\nsed -e \"/^git-svn-id:/d\"\n'\n\n\nIf you need to add Acked-by lines to, say, the last 10 commits (none of which is a merge),\nuse this command:\n\ngit filter-branch --msg-filter '\ncat &&\necho \"Acked-by: Bugs Bunny <bunny@bugzilla.org>\"\n' HEAD~10..HEAD\n\n\nThe --env-filter option can be used to modify committer and/or author identity. For example,\nif you found out that your commits have the wrong identity due to a misconfigured user.email,\nyou can make a correction, before publishing the project, like this:\n\ngit filter-branch --env-filter '\nif test \"$GITAUTHOREMAIL\" = \"root@localhost\"\nthen\nGITAUTHOREMAIL=john@example.com\nfi\nif test \"$GITCOMMITTEREMAIL\" = \"root@localhost\"\nthen\nGITCOMMITTEREMAIL=john@example.com\nfi\n' -- --all\n\n\nTo restrict rewriting to only part of the history, specify a revision range in addition to\nthe new branch name. The new branch name will point to the top-most revision that a git\nrev-list of this range will print.\n\nConsider this history:\n\nD--E--F--G--H\n/     /\nA--B-----C\n\n\nTo rewrite only commits D,E,F,G,H, but leave A, B and C alone, use:\n\ngit filter-branch ... C..H\n\n\nTo rewrite commits E,F,G,H, use one of these:\n\ngit filter-branch ... C..H --not D\ngit filter-branch ... D..H --not C\n\n\nTo move the whole tree into a subdirectory, or remove it from there:\n\ngit filter-branch --index-filter \\\n'git ls-files -s | sed \"s-\\t\\\"*-&newsubdir/-\" |\nGITINDEXFILE=$GITINDEXFILE.new \\\ngit update-index --index-info &&\nmv \"$GITINDEXFILE.new\" \"$GITINDEXFILE\"' HEAD\n\n",
                "subsections": []
            },
            "CHECKLIST FOR SHRINKING A REPOSITORY": {
                "content": "git-filter-branch can be used to get rid of a subset of files, usually with some combination\nof --index-filter and --subdirectory-filter. People expect the resulting repository to be\nsmaller than the original, but you need a few more steps to actually make it smaller, because\nGit tries hard not to lose your objects until you tell it to. First make sure that:\n\n•   You really removed all variants of a filename, if a blob was moved over its lifetime.\ngit log --name-only --follow --all -- filename can help you find renames.\n\n•   You really filtered all refs: use --tag-name-filter cat -- --all when calling\ngit-filter-branch.\n\nThen there are two ways to get a smaller repository. A safer way is to clone, that keeps your\noriginal intact.\n\n•   Clone it with git clone file:///path/to/repo. The clone will not have the removed\nobjects. See git-clone(1). (Note that cloning with a plain path just hardlinks\neverything!)\n\nIf you really don’t want to clone it, for whatever reasons, check the following points\ninstead (in this order). This is a very destructive approach, so make a backup or go back to\ncloning it. You have been warned.\n\n•   Remove the original refs backed up by git-filter-branch: say git for-each-ref\n--format=\"%(refname)\" refs/original/ | xargs -n 1 git update-ref -d.\n\n•   Expire all reflogs with git reflog expire --expire=now --all.\n\n•   Garbage collect all unreferenced objects with git gc --prune=now (or if your git-gc is\nnot new enough to support arguments to --prune, use git repack -ad; git prune instead).\n",
                "subsections": []
            },
            "PERFORMANCE": {
                "content": "The performance of git-filter-branch is glacially slow; its design makes it impossible for a\nbackward-compatible implementation to ever be fast:\n\n•   In editing files, git-filter-branch by design checks out each and every commit as it\nexisted in the original repo. If your repo has 10^5 files and 10^5 commits, but each\ncommit only modifies five files, then git-filter-branch will make you do 10^10\nmodifications, despite only having (at most) 5*10^5 unique blobs.\n\n•   If you try and cheat and try to make git-filter-branch only work on files modified in a\ncommit, then two things happen\n\n•   you run into problems with deletions whenever the user is simply trying to rename\nfiles (because attempting to delete files that don’t exist looks like a no-op; it\ntakes some chicanery to remap deletes across file renames when the renames happen via\narbitrary user-provided shell)\n\n•   even if you succeed at the map-deletes-for-renames chicanery, you still technically\nviolate backward compatibility because users are allowed to filter files in ways that\ndepend upon topology of commits instead of filtering solely based on file contents or\nnames (though this has not been observed in the wild).\n\n•   Even if you don’t need to edit files but only want to e.g. rename or remove some and thus\ncan avoid checking out each file (i.e. you can use --index-filter), you still are passing\nshell snippets for your filters. This means that for every commit, you have to have a\nprepared git repo where those filters can be run. That’s a significant setup.\n\n•   Further, several additional files are created or updated per commit by git-filter-branch.\nSome of these are for supporting the convenience functions provided by git-filter-branch\n(such as map()), while others are for keeping track of internal state (but could have\nalso been accessed by user filters; one of git-filter-branch’s regression tests does so).\nThis essentially amounts to using the filesystem as an IPC mechanism between\ngit-filter-branch and the user-provided filters. Disks tend to be a slow IPC mechanism,\nand writing these files also effectively represents a forced synchronization point\nbetween separate processes that we hit with every commit.\n\n•   The user-provided shell commands will likely involve a pipeline of commands, resulting in\nthe creation of many processes per commit. Creating and running another process takes a\nwidely varying amount of time between operating systems, but on any platform it is very\nslow relative to invoking a function.\n\n•   git-filter-branch itself is written in shell, which is kind of slow. This is the one\nperformance issue that could be backward-compatibly fixed, but compared to the above\nproblems that are intrinsic to the design of git-filter-branch, the language of the tool\nitself is a relatively minor issue.\n\n•   Side note: Unfortunately, people tend to fixate on the written-in-shell aspect and\nperiodically ask if git-filter-branch could be rewritten in another language to fix\nthe performance issues. Not only does that ignore the bigger intrinsic problems with\nthe design, it’d help less than you’d expect: if git-filter-branch itself were not\nshell, then the convenience functions (map(), skipcommit(), etc) and the --setup\nargument could no longer be executed once at the beginning of the program but would\ninstead need to be prepended to every user filter (and thus re-executed with every\ncommit).\n\nThe git filter-repo[1] tool is an alternative to git-filter-branch which does not suffer from\nthese performance problems or the safety problems (mentioned below). For those with existing\ntooling which relies upon git-filter-branch, git filter-repo also provides filter-lamely[2],\na drop-in git-filter-branch replacement (with a few caveats). While filter-lamely suffers\nfrom all the same safety issues as git-filter-branch, it at least ameliorates the performance\nissues a little.\n",
                "subsections": []
            },
            "SAFETY": {
                "content": "git-filter-branch is riddled with gotchas resulting in various ways to easily corrupt repos\nor end up with a mess worse than what you started with:\n\n•   Someone can have a set of \"working and tested filters\" which they document or provide to\na coworker, who then runs them on a different OS where the same commands are not\nworking/tested (some examples in the git-filter-branch manpage are also affected by\nthis). BSD vs. GNU userland differences can really bite. If lucky, error messages are\nspewed. But just as likely, the commands either don’t do the filtering requested, or\nsilently corrupt by making some unwanted change. The unwanted change may only affect a\nfew commits, so it’s not necessarily obvious either. (The fact that problems won’t\nnecessarily be obvious means they are likely to go unnoticed until the rewritten history\nis in use for quite a while, at which point it’s really hard to justify another flag-day\nfor another rewrite.)\n\n•   Filenames with spaces are often mishandled by shell snippets since they cause problems\nfor shell pipelines. Not everyone is familiar with find -print0, xargs -0, git-ls-files\n-z, etc. Even people who are familiar with these may assume such flags are not relevant\nbecause someone else renamed any such files in their repo back before the person doing\nthe filtering joined the project. And often, even those familiar with handling arguments\nwith spaces may not do so just because they aren’t in the mindset of thinking about\neverything that could possibly go wrong.\n\n•   Non-ascii filenames can be silently removed despite being in a desired directory. Keeping\nonly wanted paths is often done using pipelines like git ls-files | grep -v ^WANTEDDIR/\n| xargs git rm. ls-files will only quote filenames if needed, so folks may not notice\nthat one of the files didn’t match the regex (at least not until it’s much too late).\nYes, someone who knows about core.quotePath can avoid this (unless they have other\nspecial characters like \\t, \\n, or \"), and people who use ls-files -z with something\nother than grep can avoid this, but that doesn’t mean they will.\n\n•   Similarly, when moving files around, one can find that filenames with non-ascii or\nspecial characters end up in a different directory, one that includes a double quote\ncharacter. (This is technically the same issue as above with quoting, but perhaps an\ninteresting different way that it can and has manifested as a problem.)\n\n•   It’s far too easy to accidentally mix up old and new history. It’s still possible with\nany tool, but git-filter-branch almost invites it. If lucky, the only downside is users\ngetting frustrated that they don’t know how to shrink their repo and remove the old\nstuff. If unlucky, they merge old and new history and end up with multiple \"copies\" of\neach commit, some of which have unwanted or sensitive files and others which don’t. This\ncomes about in multiple different ways:\n\n•   the default to only doing a partial history rewrite (--all is not the default and few\nexamples show it)\n\n•   the fact that there’s no automatic post-run cleanup\n\n•   the fact that --tag-name-filter (when used to rename tags) doesn’t remove the old\ntags but just adds new ones with the new name\n\n•   the fact that little educational information is provided to inform users of the\nramifications of a rewrite and how to avoid mixing old and new history. For example,\nthis man page discusses how users need to understand that they need to rebase their\nchanges for all their branches on top of new history (or delete and reclone), but\nthat’s only one of multiple concerns to consider. See the \"DISCUSSION\" section of the\ngit filter-repo manual page for more details.\n\n•   Annotated tags can be accidentally converted to lightweight tags, due to either of two\nissues:\n\n•   Someone can do a history rewrite, realize they messed up, restore from the backups in\nrefs/original/, and then redo their git-filter-branch command. (The backup in\nrefs/original/ is not a real backup; it dereferences tags first.)\n\n•   Running git-filter-branch with either --tags or --all in your <rev-list options>. In\norder to retain annotated tags as annotated, you must use --tag-name-filter (and must\nnot have restored from refs/original/ in a previously botched rewrite).\n\n•   Any commit messages that specify an encoding will become corrupted by the rewrite;\ngit-filter-branch ignores the encoding, takes the original bytes, and feeds it to\ncommit-tree without telling it the proper encoding. (This happens whether or not\n--msg-filter is used.)\n\n•   Commit messages (even if they are all UTF-8) by default become corrupted due to not being\nupdated — any references to other commit hashes in commit messages will now refer to\nno-longer-extant commits.\n\n•   There are no facilities for helping users find what unwanted crud they should delete,\nwhich means they are much more likely to have incomplete or partial cleanups that\nsometimes result in confusion and people wasting time trying to understand. (For example,\nfolks tend to just look for big files to delete instead of big directories or extensions,\nand once they do so, then sometime later folks using the new repository who are going\nthrough history will notice a build artifact directory that has some files but not\nothers, or a cache of dependencies (nodemodules or similar) which couldn’t have ever\nbeen functional since it’s missing some files.)\n\n•   If --prune-empty isn’t specified, then the filtering process can create hoards of\nconfusing empty commits\n\n•   If --prune-empty is specified, then intentionally placed empty commits from before the\nfiltering operation are also pruned instead of just pruning commits that became empty due\nto filtering rules.\n\n•   If --prune-empty is specified, sometimes empty commits are missed and left around anyway\n(a somewhat rare bug, but it happens...)\n\n•   A minor issue, but users who have a goal to update all names and emails in a repository\nmay be led to --env-filter which will only update authors and committers, missing\ntaggers.\n\n•   If the user provides a --tag-name-filter that maps multiple tags to the same name, no\nwarning or error is provided; git-filter-branch simply overwrites each tag in some\nundocumented pre-defined order resulting in only one tag at the end. (A git-filter-branch\nregression test requires this surprising behavior.)\n\nAlso, the poor performance of git-filter-branch often leads to safety issues:\n\n•   Coming up with the correct shell snippet to do the filtering you want is sometimes\ndifficult unless you’re just doing a trivial modification such as deleting a couple\nfiles. Unfortunately, people often learn if the snippet is right or wrong by trying it\nout, but the rightness or wrongness can vary depending on special circumstances (spaces\nin filenames, non-ascii filenames, funny author names or emails, invalid timezones,\npresence of grafts or replace objects, etc.), meaning they may have to wait a long time,\nhit an error, then restart. The performance of git-filter-branch is so bad that this\ncycle is painful, reducing the time available to carefully re-check (to say nothing about\nwhat it does to the patience of the person doing the rewrite even if they do technically\nhave more time available). This problem is extra compounded because errors from broken\nfilters may not be shown for a long time and/or get lost in a sea of output. Even worse,\nbroken filters often just result in silent incorrect rewrites.\n\n•   To top it all off, even when users finally find working commands, they naturally want to\nshare them. But they may be unaware that their repo didn’t have some special cases that\nsomeone else’s does. So, when someone else with a different repository runs the same\ncommands, they get hit by the problems above. Or, the user just runs commands that really\nwere vetted for special cases, but they run it on a different OS where it doesn’t work,\nas noted above.\n",
                "subsections": []
            },
            "GIT": {
                "content": "Part of the git(1) suite\n",
                "subsections": []
            },
            "NOTES": {
                "content": "1. git filter-repo\nhttps://github.com/newren/git-filter-repo/\n\n2. filter-lamely\nhttps://github.com/newren/git-filter-repo/blob/master/contrib/filter-repo-demos/filter-lamely\n\n\n\nGit 2.34.1                                   02/26/2026                         GIT-FILTER-BRANCH(1)",
                "subsections": []
            }
        }
    }
}