2

Very often I need to change the date of n previous commits. Usually I do git rebase -i @~20 and then in the editor manually change pick to edit, after that run in the loop commit --amend with desired date. It all works nicely, but I would like to automate the process so that the editor would not be called at all.

The question is: how do I switch to "edit mode" automatically after git rebase?

Vasfed
  • 18,013
  • 10
  • 47
  • 53

1 Answers1

2

You can write a script that will behave like an editor and does what you want(it will be called with a temporary file and should modify it), then run the rebase with it - EDITOR=/path/to/your/script git rebase -i @~20

Also you might want to look onto git filter-branch approach suggested in How can one change the timestamp of an old commit in Git?

Community
  • 1
  • 1
Vasfed
  • 18,013
  • 10
  • 47
  • 53
  • This is the right answer for the question as asked (and `filter-branch` may be a better alternative too!). I just wanted to add one more note: the *instructions* for rebase go through `${GIT_SEQUENCE_EDITOR}` which defaults to `$(git config --get sequence.editor)`, falling back to the usual editor. This means you can set up two different automatic editors if you like (this allows you to know automatically whether you're editing the pick sequence or the commit messages). – torek Feb 06 '16 at 22:10