{"thread":{"id":"37383","subject":"[BUG] rewriting history with filter-branch --commit-filter","startedAt":"2014-08-20T08:16:11Z","lastAt":"2014-08-20T08:59:51Z","messageCount":3,"participants":["Davide Fiorentino","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"248005","messageId":"17DBA232-E993-4B3C-9952-90424976A28D@gmail.com","threadId":"37383","inReplyTo":null,"subject":"[BUG] rewriting history with filter-branch --commit-filter","fromName":"Davide Fiorentino","fromEmail":"davide.fiorentino@gmail.com","sentAt":"2014-08-20T08:16:11Z","receivedAt":"2014-08-20T08:16:11Z","isPatch":false,"sender":{"key":"davide.fiorentino@gmail.com","avatar":"https://gravatar.com/avatar/e314e7bc9824cf26157df764c7f19351dfb2747341b045aa4a0b280c0c9f0444?d=mp&s=160"},"body":"Hi,\n\nI was in the need to rewrite author name and email and commit date for a single commit and I guess I found a bug.\nI run this git-filter script\n\n$ git filter-branch --commit-filter ‘\n    if [ \"$GIT_COMMIT\"=\"9cfca27\" ]; \n        then GIT_AUTHOR_NAME=“Michelle”; \n            GIT_AUTHOR_EMAIL=“michelle@email.com”; \n            GIT_AUTHOR_DATE=\"2009-12-31T23:59:59”; \n            git commit-tree \"$@“; \n        else \n            git commit-tree \"$@“;\n    fi' HEAD\n\nand found that all history was rewritten as if “Michelle” not only commit 9cfca27.\n\nI also tried using full length commit id and a non-existing commit id: nothing changes.\nIn the following example to replicate the replicate the bug I’m using a non-existing commit id to make the effect more evident.\n\n\n$ git --version\ngit version 2.0.1\n\n$ mkdir project\n\n$ cd project\n\n$ git init\n\n$ for i in 1 2 3; do echo \"foo\" >> foo$i.txt; git add foo$i.txt; git commit -m \"foo$i\"; done\n[master (root-commit) 89dec6e] foo1\n 1 file changed, 1 insertion(+)\n create mode 100644 foo1.txt\n[master 8a3c8e5] foo2\n 1 file changed, 1 insertion(+)\n create mode 100644 foo2.txt\n[master a3ca061] foo3\n 1 file changed, 1 insertion(+)\n create mode 100644 foo3.txt\n\n$ git log --graph --all --pretty=format:'%C(yellow)%h%C(cyan)%d%Creset %s %C(white)- %an, %ar%Creset'\n* a3ca061 (HEAD, master) foo3 - David, 4 seconds ago\n* 8a3c8e5 foo2 - David, 4 seconds ago\n* 89dec6e foo1 - David, 4 seconds ago\n\n$ git filter-branch --commit-filter '\n    if [ \"$GIT_COMMIT\"=\"308add7\" ]; \n        then GIT_AUTHOR_NAME=\"Michelle\"; \n            GIT_AUTHOR_EMAIL=\"michelle@email.com\"; \n            GIT_AUTHOR_DATE=\"2009-12-31T23:59:59\"; \n            git commit-tree \"$@\"; \n        else \n            git commit-tree \"$@\";\n    fi' HEAD\n\n$ git log --graph --all --pretty=format:'%C(yellow)%h%C(cyan)%d%Creset %s %C(white)- %an, %ar%Creset'\n* 8937dff (HEAD, master) foo3 - Michelle, 4 years, 8 months ago\n* 30e494e foo2 - Michelle, 4 years, 8 months ago\n* 2a2ba4f foo1 - Michelle, 4 years, 8 months ago\n* a3ca061 (refs/original/refs/heads/master) foo3 - David, 8 seconds ago\n* 8a3c8e5 foo2 - David, 8 seconds ago\n* 89dec6e foo1 - David, 8 seconds ago\n\n$ git log\ncommit 8937dff7e6a3f5545c2242e3fd5d33acbabe6df4\nAuthor: Michelle <michelle@email.com>\nDate:   Thu Dec 31 23:59:59 2009 +0100\n\n    foo3\n\ncommit 30e494ef27f16c5456e66214ea46b780581dfb48\nAuthor: Michelle <michelle@email.com>\nDate:   Thu Dec 31 23:59:59 2009 +0100\n\n    foo2\n\ncommit 2a2ba4fd6b9627e237a12b47570a3f020a202b55\nAuthor: Michelle <michelle@email.com>\nDate:   Thu Dec 31 23:59:59 2009 +0100\n\n    foo1\n\n\nusing env-filter, I managed to rewrite the history with this:\n\n$ git filter-branch --env-filter '\n \nname=\"$GIT_AUTHOR_NAME\"\nemail=\"$GIT_AUTHOR_EMAIL\"\n \nif [ \"$GIT_COMMIT\" = \"89dec6e4bc1fb3cff694ea83f5ed900dad43449e\" ]\nthen\n    name=\"Michelle\"\n    email=\"Michelle@email.com\"\nfi\n\nexport GIT_AUTHOR_NAME=“$name\"\nexport GIT_AUTHOR_EMAIL=“$email\"\n'\n\nHope this helped.\n\nDavide"},{"id":"248006","messageId":"20140820085247.GB12999@peff.net","threadId":"37383","inReplyTo":"17DBA232-E993-4B3C-9952-90424976A28D@gmail.com","subject":"Re: [BUG] rewriting history with filter-branch --commit-filter","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2014-08-20T08:52:47Z","receivedAt":"2014-08-20T08:52:47Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Aug 20, 2014 at 10:16:11AM +0200, Davide Fiorentino wrote:\n\n> 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.\n> I run this git-filter script\n> \n> $ git filter-branch --commit-filter ‘\n>     if [ \"$GIT_COMMIT\"=\"9cfca27\" ]; \n>         then GIT_AUTHOR_NAME=“Michelle”; \n>             GIT_AUTHOR_EMAIL=“michelle@email.com”; \n>             GIT_AUTHOR_DATE=\"2009-12-31T23:59:59”; \n>             git commit-tree \"$@“; \n>         else \n>             git commit-tree \"$@“;\n>     fi' HEAD\n> \n> and found that all history was rewritten as if “Michelle” not only commit 9cfca27.\n\nThe filter snippets you provide to filter-branch are shell script. The\n`[` command (aka `test`) is just another shell command, and follows the\nusual whitespace splitting rules. In your command:\n\n  [ \"$GIT_COMMIT\"=\"9cfca27\" ]\n\nit sees only one single argument, all concatenated together. A single\nargument given to `test` is the same as `test -n`: it tells you whether\nthe string is empty, so this conditional is always true. You wanted:\n\n  [ \"$GIT_COMMIT\" = \"9cfca27\" ]\n\ninstead. The whitespace makes the \"=\" a separate argument, and the\ncommand knows it's an operator. You should also use the full commit id,\nas that is what will be in $GIT_COMMIT.\n\n-Peff\n"},{"id":"248009","messageId":"014F6E4D-96E8-451A-B7D4-379C260240FD@gmail.com","threadId":"37383","inReplyTo":"20140820085247.GB12999@peff.net","subject":"Re: [BUG] rewriting history with filter-branch --commit-filter","fromName":"Davide Fiorentino","fromEmail":"davide.fiorentino@gmail.com","sentAt":"2014-08-20T08:59:51Z","receivedAt":"2014-08-20T08:59:51Z","isPatch":false,"sender":{"key":"davide.fiorentino@gmail.com","avatar":"https://gravatar.com/avatar/e314e7bc9824cf26157df764c7f19351dfb2747341b045aa4a0b280c0c9f0444?d=mp&s=160"},"body":"Damn! I haven’t seen that missing space.\n\nThank you Peff!\n\nDavide"}]}