How do I remove all commits by certain author (committed by mistake - such an author should not be visible in the commits history).
I have found some code to rename -
git filter-branch --env-filter '
OLD_EMAIL="[email protected]"
CORRECT_NAME="name"
CORRECT_EMAIL="[email protected]"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_AUTHOR_NAME="$CORRECT_NAME"
export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags
git push --force --tags origin 'refs/heads/*'
Is there some filter not to rename but remove such commits?
You can do it like this:
Create a new branch based on the commit you want to start with:
git checkout -b <branch-name> <base-commit>
Cherry-pick all commits that don’t have the matching author:
git log --author "<name>" --invert-grep --reverse --format="format:%H" HEAD..master | xargs git cherry-pick
The log
filters out all commits made by the author and then cherry-pick
s them one after one.
Explanation for the parameters (partly quoted from git log
manpage):
--author "name"
--invert-grep
--reverse
Output the commits in reverse order. […]--format="format:%H"
Use a custom format, in this case only the commit hash