master c4dbb54ddc6b cached
4 files
5.9 KB
1.5k tokens
1 requests
Download .txt
Repository: davidfokkema/git-rewrite-author
Branch: master
Commit: c4dbb54ddc6b
Files: 4
Total size: 5.9 KB

Directory structure:
gitextract_zx6uwtv2/

├── .gitignore
├── README.rst
├── git-rewrite-author
└── setup.py

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitignore
================================================
git_rewrite_author.egg-info/
build/
dist/


================================================
FILE: README.rst
================================================
Rewrite author/committer history of a git repository
====================================================

Have you ever accidentally committed to a git repository with a broken
user config?  No?  But your co-workers have?

So, you're stuck with commits like this::

    Author: root <root@localhost>

        Hotfix on the production server.  This was urgent!

Nasty.  Or::

    Author: John Doe <john@localhost>

        Fixed bug #1.  Committed on my laptop.

Would it be nice to rewrite history?  And take care of committers, as
well as of authors?  Without all the hassle?  Now, you can!

Usage::

    $ git rewrite-author -w "John Doe <john@localhost>" "John Doe <dearjohn@example.com>"

Then, to push your changes to the default remote::

    $ git push --force

Not using --force may duplicate the commits on origin, not replace them, so be careful with that.

You're not sure which authors/committers are hidden in your repository?
What about::

    $ git rewrite-author -l

Tags are rewritten automagically, too!

After you've checked everything is okay, you may wish to remove the original refs backed up by git --filter-branch::

    $ git for-each-ref --format="%(refname)" refs/original/ | xargs -r -n 1 git update-ref -d


Enjoy!


Installation
------------

Clone or download this repository and run::

    $ python setup.py install


================================================
FILE: git-rewrite-author
================================================
#!/usr/bin/env python

"""Rewrite author/committer history of a git repository

Have you ever accidentally committed to a git repository with a broken
user config?  No?  But your co-workers have?

So, you're stuck with commits like this::

    Author: root <root@localhost>

        Hotfix on the production server.  This was urgent!

Nasty.  Or::

    Author: John Doe <john@localhost>

        Fixed bug #1.  Committed on my laptop.

Would it be nice to rewrite history?  And take care of committers, as
well as of authors?  Without all the hassle?  Now, you can!

Usage::

    $ git rewrite-author -w "John Doe <john@localhost>" "John Doe <dearjohn@example.com>"

Then, to push your changes to the default remote::

    $ git push --force

Not using --force may duplicate the commits on origin, not replace them, so be careful with that.

You're not sure which authors/committers are hidden in your repository?
What about::

    $ git rewrite-author -l

Tags are rewritten automagically, too!

Enjoy!


Installation
------------

Clone or download this repository and run::

    $ python setup.py install

"""
import argparse
import re
import subprocess
import textwrap


description = "Rewrite author/committer in git history"
epilog = """
Example:

$ git-rewrite-author -w "Name <me@localhost>" "Full Name <me@example.com>"
"""

git_rewrite_command = """git filter-branch --env-filter '
    if [ "$GIT_AUTHOR_NAME" = "%(old_name)s" -a "$GIT_AUTHOR_EMAIL" = "%(old_email)s" ]; then
        export GIT_AUTHOR_NAME="%(new_name)s";
        export GIT_AUTHOR_EMAIL="%(new_email)s";
    fi;
' --tag-name-filter cat -f -- --all"""
git_log_command = "git log --pretty=full"


def parse_args():
    """Parse command-line arguments"""

    parser = argparse.ArgumentParser(description=description,
                         epilog=epilog,
                         formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument('-l', '--list', action='store_true',
                        help="List all authors and committers")
    parser.add_argument('-w', '--rewrite', nargs=2,
                        metavar=('old', 'new'), type=str,
                        help="Rewrite authors and committers")
    return parser.parse_args()


def main(args):
    """Rewrite history using args"""

    if args.list:
        list_git_authors()
    elif args.rewrite:
        old_name, old_email = parse_author_arg(args.rewrite[0])
        new_name, new_email = parse_author_arg(args.rewrite[1])

        rewrite_git_author(old_name, old_email, new_name, new_email)
        rewrite_git_committer(old_name, old_email, new_name, new_email)
    else:
        print("Doing nothing.  Invoke with -h for help.")


def parse_author_arg(arg):
    """Parse name/email argument"""

    name, email = re.match("(.+)\s<(.*)>", arg).groups()
    return name, email


def rewrite_git_author(old_name, old_email, new_name, new_email):
    """Rewrite author history in git"""

    command = git_rewrite_command % \
        { 'old_name': old_name, 'old_email': old_email, 'new_name': new_name, 'new_email': new_email}
    subprocess.call(command, shell=True)


def rewrite_git_committer(old_name, old_email, new_name, new_email):
    """Rewrite committer history in git"""

    command = git_rewrite_command.replace('AUTHOR', 'COMMITTER') % \
        { 'old_name': old_name, 'old_email': old_email, 'new_name': new_name, 'new_email': new_email}
    subprocess.call(command, shell=True)


def list_git_authors():
    """List authors and committers"""

    output = subprocess.check_output(git_log_command.split(' '))
    matches = re.findall(b'(Author|Commit): (.*)\n', output)
    names = [u[1].decode('utf-8') for u in matches]
    unique_names = sorted(set(names))

    print("The following authors and committers have contributed:\n")
    for name in unique_names:
        print(name)


if __name__ == '__main__':
    args = parse_args()
    main(args)


================================================
FILE: setup.py
================================================
#!/usr/bin/env python

from setuptools import setup

setup(name='git rewrite author',
      version='1.0',
      description='Rewrite author/committer history of a git repository',
      author='David Fokkema',
      author_email='davidfokkema@icloud.com',
      url='https://github.com/davidfokkema/git-rewrite-author',
      classifiers=['Intended Audience :: Developers',
                   'Environment :: Console',
                   'Programming Language :: Python :: 2.7',
                   'Topic :: Software Development :: Version Control',
                   'License :: OSI Approved :: GNU General Public License v3 (GPLv3)'],
      scripts=['git-rewrite-author'])
Download .txt
gitextract_zx6uwtv2/

├── .gitignore
├── README.rst
├── git-rewrite-author
└── setup.py
Condensed preview — 4 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (6K chars).
[
  {
    "path": ".gitignore",
    "chars": 42,
    "preview": "git_rewrite_author.egg-info/\nbuild/\ndist/\n"
  },
  {
    "path": "README.rst",
    "chars": 1349,
    "preview": "Rewrite author/committer history of a git repository\n====================================================\n\nHave you ever"
  },
  {
    "path": "git-rewrite-author",
    "chars": 3936,
    "preview": "#!/usr/bin/env python\n\n\"\"\"Rewrite author/committer history of a git repository\n\nHave you ever accidentally committed to "
  },
  {
    "path": "setup.py",
    "chars": 677,
    "preview": "#!/usr/bin/env python\n\nfrom setuptools import setup\n\nsetup(name='git rewrite author',\n      version='1.0',\n      descrip"
  }
]

About this extraction

This page contains the full source code of the davidfokkema/git-rewrite-author GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 4 files (5.9 KB), approximately 1.5k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!