Created
April 26, 2018 20:14
-
-
Save drmats/d3b27bcc3dc32c5951310f015129e256 to your computer and use it in GitHub Desktop.
Git history rewrite (change author and e-mail)
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
#!/bin/sh | |
# https://help.github.com/articles/changing-author-info/ | |
git filter-branch --env-filter ' | |
OLD_EMAIL="your-old-email@example.com" | |
CORRECT_NAME="Your Correct Name" | |
CORRECT_EMAIL="your-correct-email@example.com" | |
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ] | |
then | |
export GIT_COMMITTER_NAME="$CORRECT_NAME" | |
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL" | |
fi | |
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ] | |
then | |
export GIT_AUTHOR_NAME="$CORRECT_NAME" | |
export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL" | |
fi | |
' --tag-name-filter cat -- --branches --tags |
GPG sign all commits and tags in the history:
$ git filter-branch -f --commit-filter 'git commit-tree -S "$@";' -- --all
on all branches:
$ git filter-branch -f --commit-filter 'git commit-tree -S "$@";' --tag-name-filter cat -- --branches --tags
$ git branch -d branch_name
$ git push -d origin branch_name
$ git remote prune origin
Replace master
with other_branch
:
$ git branch -f master other_branch
Delete tagname
locally and from remote:
git push --delete origin tagname
git tag --delete tagname
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ git clone --bare git@github.com:user/repo.git
$ cd repo.git
-- run script --
$ git push --force --tags origin 'refs/heads/*'