Created
July 27, 2023 01:49
-
-
Save raffecat/ff5ea648315a75324aa4216d8b2c3d22 to your computer and use it in GitHub Desktop.
Git rebase to fix up author information on commits
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Git rebase is a weird 3-way thing that compares local commits to upstream commits. | |
# Yes really. So if you just want to edit some local commits, you need an upstream | |
# branch with exactly the same commits on it, to avoid git doing weird stuff. | |
# There doesn't seem to be any "local only" option in git rebase. | |
git config user.name 'Full Name' | |
git config user.email '[email protected]' | |
git branch temp-1 | |
# this is the critical step: | |
git push -u origin temp-1 | |
# git rebase -i --root --exec "git commit --amend --reset-author --no-edit" | |
# the following preserves all commit and author timestamps! | |
git -c rebase.instructionFormat='%s%nexec GIT_COMMITTER_DATE="%cD" GIT_AUTHOR_DATE="%aD" git commit --amend --no-edit --reset-author' rebase --root | |
git push -f origin temp-1 | |
# in my case I wanted to fix up main: | |
git push -f origin main | |
git fetch --all | |
git branch --delete temp-1 | |
git push origin --delete temp-1 | |
git gc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment