Home > Uncategorized > Changing git committers and authors with python

Changing git committers and authors with python

Here is a python script I’m using to fix author and committer names in a git repository.

#! /usr/bin/python
import os, sys
from subprocess import *

user_map = {
"cartman": ("Eric Cartman", "eric.cartman@southpark.net")
"kenny": ("Kenny McCormick", "kenny.mccormick@southpark.net")
}

def setenv(var):
    user = user_map.get(os.environ["GIT_%s_NAME" % var])
    if user:
        os.environ["GIT_%s_NAME" % var] = user[0]
        os.environ["GIT_%s_EMAIL" % var] = user[1]

setenv("AUTHOR")
setenv("COMMITTER")

cmd = ['git', 'commit-tree']
cmd.extend(sys.argv[1:])
call(cmd)

Here is how to use this script:

git filter-branch --commit-filter '/path/to/authors.py "$@"' --tag-name-filter cat -- --all
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
Advertisements
Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: