Following my previous article, I had some interesting comments introducing me to
git-filter-branch (which is a new function coming from cogito’s
cg-admin-rewritehist). This command is really designed to rewrite the history and you can do much more changes… it enabled me to fix the dates/authors/committers/logs of all the commits that were created with git_load_dirs. It can also be used to add one or more “parent commits” to any commit.
In parallel I discovered some problems with the git repository that I created: the tags were no more pointing to my master branch. This is because
git rebase won’t convert them while rewriting history.
This lead me to redo everything from scratch. This time I used
git-filter-branch instead. The man page even gives an example of how to link two branches together as if one was the predecessor of the other. Here’s how you can do it: let’s bind together “old” and “new”… the resulting branch will be “new-rewritten”.
$ git rev-parse old 0975870bb1631379f2da798fa78736a4fe32960a $ git checkout new $ git-filter-branch --tag-name-filter=cat --parent-filter \ "sed -e 's/^$/-p 0975870bb1631379f2da798fa78736a4fe32960a/'" \ new-rewritten [...] Rewritten history saved to the new-rewritten branch
Short explanation: the only commit without a parent commit (thus matching the empty regex “^$”) is the root commit and this one is changed to have a parent (-p) which is the last commit of the branch “old”.
At the end, you remove all the temporary branches, keep only what’s needed and repack everything to save space:
$ git branch -D old new
$ git prune
$ git repack -a -d