* [BUG] rewriting history with filter-branch --commit-filter
@ 2014-08-20 8:16 Davide Fiorentino
2014-08-20 8:52 ` Jeff King
0 siblings, 1 reply; 3+ messages in thread
From: Davide Fiorentino @ 2014-08-20 8:16 UTC (permalink / raw)
To: git
Hi,
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.
I also tried using full length commit id and a non-existing commit id: nothing changes.
In the following example to replicate the replicate the bug I’m using a non-existing commit id to make the effect more evident.
$ git --version
git version 2.0.1
$ mkdir project
$ cd project
$ git init
$ for i in 1 2 3; do echo "foo" >> foo$i.txt; git add foo$i.txt; git commit -m "foo$i"; done
[master (root-commit) 89dec6e] foo1
1 file changed, 1 insertion(+)
create mode 100644 foo1.txt
[master 8a3c8e5] foo2
1 file changed, 1 insertion(+)
create mode 100644 foo2.txt
[master a3ca061] foo3
1 file changed, 1 insertion(+)
create mode 100644 foo3.txt
$ git log --graph --all --pretty=format:'%C(yellow)%h%C(cyan)%d%Creset %s %C(white)- %an, %ar%Creset'
* a3ca061 (HEAD, master) foo3 - David, 4 seconds ago
* 8a3c8e5 foo2 - David, 4 seconds ago
* 89dec6e foo1 - David, 4 seconds ago
$ git filter-branch --commit-filter '
if [ "$GIT_COMMIT"="308add7" ];
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
$ git log --graph --all --pretty=format:'%C(yellow)%h%C(cyan)%d%Creset %s %C(white)- %an, %ar%Creset'
* 8937dff (HEAD, master) foo3 - Michelle, 4 years, 8 months ago
* 30e494e foo2 - Michelle, 4 years, 8 months ago
* 2a2ba4f foo1 - Michelle, 4 years, 8 months ago
* a3ca061 (refs/original/refs/heads/master) foo3 - David, 8 seconds ago
* 8a3c8e5 foo2 - David, 8 seconds ago
* 89dec6e foo1 - David, 8 seconds ago
$ git log
commit 8937dff7e6a3f5545c2242e3fd5d33acbabe6df4
Author: Michelle <michelle@email.com>
Date: Thu Dec 31 23:59:59 2009 +0100
foo3
commit 30e494ef27f16c5456e66214ea46b780581dfb48
Author: Michelle <michelle@email.com>
Date: Thu Dec 31 23:59:59 2009 +0100
foo2
commit 2a2ba4fd6b9627e237a12b47570a3f020a202b55
Author: Michelle <michelle@email.com>
Date: Thu Dec 31 23:59:59 2009 +0100
foo1
using env-filter, I managed to rewrite the history with this:
$ git filter-branch --env-filter '
name="$GIT_AUTHOR_NAME"
email="$GIT_AUTHOR_EMAIL"
if [ "$GIT_COMMIT" = "89dec6e4bc1fb3cff694ea83f5ed900dad43449e" ]
then
name="Michelle"
email="Michelle@email.com"
fi
export GIT_AUTHOR_NAME=“$name"
export GIT_AUTHOR_EMAIL=“$email"
'
Hope this helped.
Davide
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [BUG] rewriting history with filter-branch --commit-filter
2014-08-20 8:16 [BUG] rewriting history with filter-branch --commit-filter Davide Fiorentino
@ 2014-08-20 8:52 ` Jeff King
2014-08-20 8:59 ` Davide Fiorentino
0 siblings, 1 reply; 3+ messages in thread
From: Jeff King @ 2014-08-20 8:52 UTC (permalink / raw)
To: Davide Fiorentino; +Cc: git
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-08-20 9:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-20 8:16 [BUG] rewriting history with filter-branch --commit-filter Davide Fiorentino
2014-08-20 8:52 ` Jeff King
2014-08-20 8:59 ` Davide Fiorentino
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).