Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use 'git filter-branch' to correct committer dates in last N commits?

I recently needed to apply 16 patches to my repo, using 'git am', and I was careful to use '--committer-date-is-author-date' for each one. However, I also needed to adjust the commit message for each am'd patch, and-- after I was done with all 16-- I discovered that 'commit --amend' bumped the committer timestamp for each of them.

I eventually learned that my problem could be solved in one fell swoop with

git rebase --committer-date-is-author-date <SHA-of-commit-prior-to-patches>

but not before trying to solve my problem with 'filter-branch', which did not work. I am curious what I did wrong. Here is my attempt:

git filter-branch --env-filter \
    'export GIT_COMMITTER_DATE=$GIT_AUTHOR_DATE' SHA1..HEAD

And here is the result:

Rewrite 1c52265d1f06bd67e0fed1c09e1e75249424476e (1/15)/usr/lib/git-core/git-filter-branch: 1: export: -0500: bad variable name

What did I do wrong? Am I not allowed to set/export one variable to be the value of another, within an env-filter? Note that I adapted my approach from one that conditionally changed both GIT_AUTHOR_DATE and GIT_COMMITTER_DATE if $GIT_COMMIT matched a particular SHA, but in that case both GIT_*_DATE variables were being set to a constant string, rather than another variable.

like image 495
Ryan V. Bissell Avatar asked Jul 18 '14 07:07

Ryan V. Bissell


1 Answers

The value of $GIT_AUTHOR_DATE contains spaces, so you have to quote it (-0500 is your time zone offset):

git filter-branch --env-filter \
  'export GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"' SHA1..HEAD
like image 170
knittl Avatar answered Oct 11 '22 22:10

knittl