Before publishing a project I would like to clean up the repository, which means:
- removing all commits older than a certain tag (but leaving the rest of the history and the current version as they are)
- changing the author and commiter names and e-mail adresses to something meaningful
The tree is quite simple, there is just one branch (except for another branch that I don't care about). But there are the following complications:
- I have tags (with descriptions) that I want to keep (but here, too, the tagger name and e-mail address shall be changed while keeping the time stamp)
- I have references (commit messages like "fixes a bug introduced in commit X") that need to be adapted
- I have notes (like "turned out this introduced a bug which was fixed in commit Y") that I want to keep
I have found this answer to crop the history:
$ git checkout --orphan temp <newroot-sha1> $ git commit -C <newroot-sha1> $ git commit --ammend $ git rebase --onto temp <newroot-sha1> master $ git checkout master $ git branch -d temp
While this does crop the beginning as desired, it creates a new history without tags and notes and the references are not updated. I have tried git rebasetags but it does not keep the tags' descriptions and it assigns the tags to a wrong commit if two commits have the same commit message. It does not address the issue of notes and references.
I have found this answer to change name and e-mail of commits. It changes the name and e-mail of the commits as desired and although it rewirtes history it even keeps the tags with their messages but it does not change tagger name and e-mail address of the tags. It does not keep the notes and it does not update the references.
$ git filter-branch --env-filter ' WRONG_EMAIL="old-email" NEW_NAME="new-name" NEW_EMAIL="new-email" if [ "$GIT_COMMITTER_EMAIL" = "$WRONG_EMAIL" ] then export GIT_COMMITTER_NAME="$NEW_NAME" export GIT_COMMITTER_EMAIL="$NEW_EMAIL" fi if [ "$GIT_AUTHOR_EMAIL" = "$WRONG_EMAIL" ] then export GIT_AUTHOR_NAME="$NEW_NAME" export GIT_AUTHOR_EMAIL="$NEW_EMAIL" fi ' --tag-name-filter cat -- --branches --tags
How can I crop the history and change the name and e-mail address of all commits and tags while keeping tags and notes (and their time stamps) and update the sha1 ids of commits mentioned in commit messages and notes? (I can't see an option to show the author of a note. Do notes have an author? If so, I would want to change it, too.)