If I create a Git repository and publish it publicly (e.g. on GitHub etc.), and I get a request from a contributor to the repository to remove or obscure their name for whatever reason, is there a way of doing so easily?
Basically, I have had such a request and may want to replace their name and e-mail address with something like "Anonymous Contributor" or maybe a SHA-1 hash of their e-mail address or something like that.
Jeff is quite right, the right track is git filter-branch. It expects a script that plays with the environment variables. For your use case, you probably want something like this:
git filter-branch --env-filter '
if [ "$GIT_AUTHOR_NAME" = "Niko Schwarz" ]; then \
export GIT_AUTHOR_NAME="Jon Doe" GIT_AUTHOR_EMAIL="[email protected]"; \
fi
'
You can test that it works like this:
$ cd /tmp
$ mkdir filter-branch && cd filter-branch
$ git init
Initialized empty Git repository in /private/tmp/filter-branch/.git/
$
$ touch hi && git add . && git commit -m bla
[master (root-commit) 081f7f5] bla
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 hi
$ echo howdi >> hi && git commit -a -m bla
[master a466a18] bla
1 files changed, 1 insertions(+), 0 deletions(-)
$ git log
commit a466a18e4dc48908f7ba52f8a373dab49a6cfee4
Author: Niko Schwarz <[email protected]>
Date: Thu Aug 12 09:43:44 2010 +0200
bla
commit 081f7f50921edc703b55c04654218fe95d09dc3c
Author: Niko Schwarz <[email protected]>
Date: Thu Aug 12 09:43:34 2010 +0200
bla
$
$ git filter-branch --env-filter '
> if [ "$GIT_AUTHOR_NAME" = "Niko Schwarz" ]; then \
> export GIT_AUTHOR_NAME="Jon Doe" GIT_AUTHOR_EMAIL="[email protected]"; \
> fi
> '
Rewrite a466a18e4dc48908f7ba52f8a373dab49a6cfee4 (2/2)
Ref 'refs/heads/master' was rewritten
$ git log
commit 5f0dfc0dc9a325a3f3aaf4575369f15b0fb21fe9
Author: Jon Doe <[email protected]>
Date: Thu Aug 12 09:43:44 2010 +0200
bla
commit 3cf865fa0a43d2343b4fb6c679c12fc23f7c6015
Author: Jon Doe <[email protected]>
Date: Thu Aug 12 09:43:34 2010 +0200
bla
Please beware. There's no way to delete the author's name without invalidating all later commit hashes. That will make later merging a pain for people that have been using your repository.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With