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

Re: [BUG] rewriting history with filter-branch --commit-filter

From
Jeff King <peff@peff.net>
Date
Aug 20, 2014, 08:52 UTC
Message-ID
<20140820085247.GB12999@peff.net>
In-Reply-To
<17DBA232-E993-4B3C-9952-90424976A28D@gmail.com>
On Wed, Aug 20, 2014 at 10:16:11AM +0200, Davide Fiorentino wrote:
Show 14 quoted lines
> I was in the need to rewrite author name and email and commit date for a single commit and I guess I found a bug.
> I run this git-filter script
> 
> $ git filter-branch --commit-filter ‘
>     if [ "$GIT_COMMIT"="9cfca27" ]; 
>         then GIT_AUTHOR_NAME=“Michelle”; 
>             GIT_AUTHOR_EMAIL=“michelle@email.com”; 
>             GIT_AUTHOR_DATE="2009-12-31T23:59:59”; 
>             git commit-tree "$@“; 
>         else 
>             git commit-tree "$@“;
>     fi' HEAD
> 
> and found that all history was rewritten as if “Michelle” not only commit 9cfca27.

The filter snippets you provide to filter-branch are shell script. The `[` command (aka `test`) is just another shell command, and follows the usual whitespace splitting rules. In your command:

  [ "$GIT_COMMIT"="9cfca27" ]

it sees only one single argument, all concatenated together. A single argument given to `test` is the same as `test -n`: it tells you whether the string is empty, so this conditional is always true. You wanted:

  [ "$GIT_COMMIT" = "9cfca27" ]

instead. The whitespace makes the "=" a separate argument, and the command knows it's an operator. You should also use the full commit id, as that is what will be in $GIT_COMMIT.

-Peff
Previous: Davide FiorentinoNext: Davide Fiorentino
Message 2 of 3 in “[BUG] rewriting history with filter-branch --commit-filter”
  1. Davide FiorentinoAug 20, 2014
  2. Jeff KingAug 20, 2014
  3. Davide FiorentinoAug 20, 2014

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.