Change git user in history

From snippet wiki
Jump to navigation Jump to search

If you had a wrong user email setting and committed and pushed already:

To get back to the 5th last commit:

git rebase -i HEAD~5

Now you can change the pick keyword on each line to edit where it was wrong. Leave the editor and now you iterate via:

git commit --amend --author="Kai Kretschmann <kai@example.com>"
git rebase --continue

And finally get it back to the remote storage:

git push -f

Tag moving

After rebasing, all tags from that point on will be unconnected. So they can't be added again but have to be forced. So moving a tag like version/0.0.2 to a new commit hash id of 63eff6a is like this:

$git tag -f -a version/0.0.2 63eff6a
Updated tag 'version/0.0.2' (was 8078562)
$git push --tags --force