Script to rebuild git history, applying code cleanup to every version

Has anyone got a script for git that can go through the history, check out each version, apply a cleanup script, then check the cleaned version into another repository?

I have some code which I’ve been developing, but I haven’t been consistent with code formatting e.g. tabs vs spaces etc. I’d like to rewrite my entire history to be consistent with the new standards.

  • Are there any free cmd-line scripts which can re-format PHP source-code?
  • How to auto-format Java code
  • Is there a text editor that will “pretty print” for display without changing the underlying text?
  • Merge strategy for whitespace only changes?
  • GIT: restore formatting from master branch but keep non-formatting changes
  • Committing when changing source formatting?
  • Is there a VIM Git timeline?
  • Create fast-export package from Mercurial repository
  • git fetch, FETCH_HEAD and origin/master
  • Git rerere file pattern?
  • git remove file from repository but leave it on file system
  • Why does `git merge-base` prepares a hypothetical merge commit when more than 3 commits are supplied?
  • One Solution collect form web for “Script to rebuild git history, applying code cleanup to every version”

    The git filter-branch command does what you need.

    For example:

    # Make a backup!
    cp -r <repo> <repo>.backup
    cd <repo>
    # Replace tabs with two spaces in all .cpp and .h files in all branches.
    git filter-branch --tree-filter \
      "find \( -iname '*.cpp' -o -iname '*.h' \) \
       -exec sed -i -re 's/\t/  /g' {} \;" -- --all
    # Delete branch backups created by 'git filter-branch'.
    # From the end of `man git filter-branch`; more cleanup
    # suggestions there.
    git for-each-ref --format="%(refname)" refs/original/ | \
      xargs -n 1 git update-ref -d
    # You still have ../<repo>.backup, in case something went wrong.
    

    But be careful… this transforms the git repository.
    If somebody has a clone… it will not be connected to your new repo anymore.
    From man git filter-branch:

    WARNING! The rewritten history will have different object names for
    all the objects and will not converge with the original branch. You
    will not be able to easily push and distribute the rewritten branch
    on top of the original branch. Please do not use this command if
    you do not know the full implications, and avoid using it anyway,
    if a simple single commit would suffice to fix your problem. (See
    the “RECOVERING FROM UPSTREAM REBASE” section in git-rebase(1) for
    further information about rewriting published history.)

    Git Baby is a git and github fan, let's start git clone.