Skip to content

Instantly share code, notes, and snippets.

@drmats
Created April 26, 2018 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drmats/d3b27bcc3dc32c5951310f015129e256 to your computer and use it in GitHub Desktop.
Save drmats/d3b27bcc3dc32c5951310f015129e256 to your computer and use it in GitHub Desktop.
Git history rewrite (change author and e-mail)
#!/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
@drmats
Copy link
Author

drmats commented Apr 26, 2018

$ git clone --bare git@github.com:user/repo.git
$ cd repo.git
-- run script --
$ git push --force --tags origin 'refs/heads/*'

@drmats
Copy link
Author

drmats commented Apr 26, 2018

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

@drmats
Copy link
Author

drmats commented May 8, 2018

$ git branch -d branch_name
$ git push -d origin branch_name
$ git remote prune origin

@drmats
Copy link
Author

drmats commented Jul 12, 2018

Replace master with other_branch:
$ git branch -f master other_branch

@drmats
Copy link
Author

drmats commented Sep 16, 2018

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