Skip to content

Instantly share code, notes, and snippets.

@Winslett
Last active November 30, 2015 12:56
Show Gist options
  • Save Winslett/3b90a7bb1cd00a3f66a0 to your computer and use it in GitHub Desktop.
Save Winslett/3b90a7bb1cd00a3f66a0 to your computer and use it in GitHub Desktop.
#!/bin/sh
# branch from https://gist.github.com/pozorvlak/8784840
# Suppose you want to do blind reviewing of code (eg for job interview
# purposes). Unfortunately, the candidates' names and email addresses are
# stored on every commit! You probably want to assess each candidate's version
# control practices, so just `rm -rf .git` throws away too much information.
# Here's what you can do instead.
# Rewrite all commits to hide the author's name and email
for branch in `ls .git/refs/heads`; do
# We may be doing multiple rewrites, so we must force subsequent ones.
# We're throwing away the backups anyway.
git filter-branch -f --env-filter '
export GIT_AUTHOR_NAME="Anonymous Candidate"
export GIT_AUTHOR_EMAIL="anon@example.com"
export GIT_COMMITTER_NAME="anon@example.com"
export GIT_COMMITTER_EMAIL="anon@example.com"
' $branch
done
# Delete the old commits
rm -rf .git/refs/original/
# Delete remotes, which might point to the old commits
for r in `git remote`; do git remote rm $r; done
# Your old commits will now no longer show up in GitK, `git log` or `git
# reflog`, but can still be found using `git show $commit-id`.
tail -n 1 ./.git/logs/HEAD | tee ./.git/logs/HEAD
tail -n 1 ./.git/logs/refs/heads/master | tee ./.git/logs/refs/heads/master
git gc --aggressive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment