I recently forked, committed, and made a pull request to a public repository where I am not a collaborator. My pull request hasn't been merged yet.
Looking through my commits, I realized I committed using the wrong author name and I want to fix it. I tried doing a rebase, which works great:
git rebase -i HEAD~7
Then I edited
all the commits in question and, based on this answer, successfully changed the author of the commits.
git commit --amend --author "James <email@example.com>" --no-edit && \
git rebase --continue
Everything is good so far, but I noticed this changes the commit times to the current time. I want to preserve the previous timestamps. I tried following this answer, but filter-branch
appears to have changed the hashes for the entire repository.
I probably shouldn't force push this. And even if I did, it probably would make it so that my pull request couldn't be merged. So, I tried looking for a way to run filter-branch
on the last few commits on the branch, but I couldn't find anything. I tried:
git filter-branch --env-filter 'GIT_COMMITTER_DATE=$GIT_AUTHOR_DATE; export GIT_COMMITTER_DATE' HEAD~7
But that doesn't work. It exits with the error message:
Which ref do you want to rewrite?
What should I try to do? Is this possible?
Should I look into the --committer-date-is-author-date
flag for the rebase? What does that do?