Liam Healy (lhealy) wrote,
Liam Healy

Sanitizing history in git

It may happen that you wish to replace some string throughout a git repository and its history. This can be done with a combination of rpl and git filter-branch. The former recursively replaces strings in a directory and the latter applies it to all items in the history. So for example,
git filter-branch --tree-filter 'rpl -iR oldstring newstring *' HEAD

will do the job. If this branch tracks a remote, then untrack it,
  git remote rm origin
  rm -rf .git/refs/original

Now this is a freestanding branch which can be pushed to a new remote. Note that everyone who cloned from an existing remote that has been replaced will need to discard their files and clone again, because all the IDs for the entire history will have changed. Also it appears that newstring has to be non-empty; I tried "" but it doesn't work in filter-branch because rpl wants to query the user to make sure it's OK to replace with an empty string.
Tags: git

  • cl-plplot for simple x-y plots from Lisp

    I had need recently to create quick x-y plots on the screen. I have been generating TikZ and PGFplots from Lisp for journal and conference papers…

  • cffi-libffi in latest CFFI release 0.11.0

    A week ago CFFI version 0.11.0 was released. This includes cffi-libffi, which permits calling and returning with structures by value. It replaces an…

  • mem-aref and mem-aptr in CFFI

    The master branch of CFFI has the cffi-libffi system, which permits passing and returning structures by value. As part of that addition, some of the…

  • Post a new comment


    default userpic

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.