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

Re: [PATCH] Documentation: filter-branch env-filter example

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 14, 2013, 20:29 UTC
Message-ID
<7vy5eqy6z3.fsf@alter.siamese.dyndns.org>
In-Reply-To
<511D3C33.6070902@hell.org.pl>
Tadeusz Andrzej Kadłubowski  <yess@hell.org.pl> writes:
> filter-branch --env-filter example that shows how to change the email address
> in all commits by a certain developer.
> ---
Thanks.  Sign-off?
Show 17 quoted lines
>  Documentation/git-filter-branch.txt | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
>
> diff --git a/Documentation/git-filter-branch.txt b/Documentation/git-filter-branch.txt
> index dfd12c9..2664cec 100644
> --- a/Documentation/git-filter-branch.txt
> +++ b/Documentation/git-filter-branch.txt
> @@ -329,6 +329,19 @@ git filter-branch --msg-filter '
>  ' HEAD~10..HEAD
>  --------------------------------------------------------
>
> +You can modify committer/author personal information using `--env-filter`.
> +For example, to update some developer's email address use this command:
> +
> +--------------------------------------------------------
> +git filter-branch --env-filter '
> +	if [ $GIT_AUTHOR_EMAIL = john@old.example.com ]
Quote the variable in double-quotes, like this:
	if [ "$GIT_AUTHOR_EMAIL" = john@old.example.com ]

Otherwise the comparison will break, if the e-mail part had a whitespace in it, or if it were empty, which is an example of a more likely situation where you would want to fix commits using a procedure like this, no?

But more on the example later...
Show 7 quoted lines
> +	then
> +		GIT_AUTHOR_EMAIL=john@new.example.com
> +	fi
> +	export GIT_AUTHOR_EMAIL
> +' -- --all
> +--------------------------------------------------------
> +

I do not think an illustration of env-filter is a bad addition per-se, but the sample scenario is not a realistic one. No sane project should be encouraged to rewrite their entire history every time one of the contributors change his e-mail address. That is what the mailmap mechanism is for.

The only scenario that justifies use of the given sample I can think of is to rewrite the author and committer in an unpublished project because you noticed that you forgot to set user.name and user.email up before you created these commits correctly.

Taking all of the above, the added text may look more like this, I think:

	The `--env-filter` can be used to modify committer and/or
	author identity.  For example, if you found out that your
	commits have wrong identity of yours due to misconfigured
	user.email, you can make correction, before publishing the
	project, like this:
	--------------------------------------------------------
        git filter-branch --env-filter '
        	if test "$GIT_AUTHOR_EMAIL" = "root@localhost"
                then
			GIT_AUTHOR_EMAIL=yess@example.com
			export GIT_AUTHOR_EMAIL
		fi
        	if test "$GIT_COMMITTER_EMAIL" = "root@localhost"
                then
			GIT_COMMITTER_EMAIL=yess@example.com
			export GIT_COMMITTER_EMAIL
		fi
	' -- --all
	--------------------------------------------------------

By the way, I left the "export" in; "git filter-branch --help" explicitly says that you need to re-export it. But I am not sure if they are necessary, especially after 3c730fab2cae (filter-branch: use git-sh-setup's ident parsing functions, 2012-10-18) by Peff, which added extra "export" to make sure all six identity variables are exported. After applying the above rewrite, we may want to do the following as a separate, follow-up patch.

 Documentation/git-filter-branch.txt | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/Documentation/git-filter-branch.txt b/Documentation/git-filter-branch.txt
index 8ebe999..066548e 100644
--- a/Documentation/git-filter-branch.txt
+++ b/Documentation/git-filter-branch.txt
@@ -83,8 +83,7 @@ OPTIONS
 	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 linkgit:git-commit-tree[1] for details).  Do not forget
-	to re-export the variables.
+	variables (see linkgit:git-commit-tree[1] for details).
 
 --tree-filter <command>::
 	This is the filter for rewriting the tree and its contents.
@@ -340,12 +339,10 @@ git filter-branch --env-filter '
 	if test "$GIT_AUTHOR_EMAIL" = "root@localhost"
 	then
 		GIT_AUTHOR_EMAIL=yess@example.com
-		export GIT_AUTHOR_EMAIL
 	fi
 	if test "$GIT_COMMITTER_EMAIL" = "root@localhost"
 	then
 		GIT_COMMITTER_EMAIL=yess@example.com
-		export GIT_COMMITTER_EMAIL
 	fi
 ' -- --all
 --------------------------------------------------------
Previous: Tadeusz Andrzej KadłubowskiNext: Jeff King
Message 2 of 5 in “Documentation: filter-branch env-filter example”
  1. Documentation: filter-branch env-filter exampleTadeusz Andrzej Kadłubowski, Feb 14, 2013
  2. Junio C HamanoFeb 14, 2013
  3. Jeff KingFeb 14, 2013
  4. Jeff KingFeb 14, 2013
  5. Junio C HamanoFeb 14, 2013

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.