Re: [BUG] rewriting history with filter-branch --commit-filter
From: Jeff King <hidden>
Date: 2016-06-15 23:02:18
On Wed, Aug 20, 2014 at 10:16:11AM +0200, Davide Fiorentino wrote:
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