I am using a git repository with github. With all the commits and logs I have in the repository , now I need to remove all the commits from a specific user ( say User1) . How do I remove all his commits ?
Yes. The man page of git filter-branch
provides a ready-made example: this removes all commits from "Darl McBribe" from the working tree (in your case, this would be User1
).
git filter-branch --commit-filter '
if [ "$GIT_AUTHOR_NAME" = "Darl McBribe" ];
then
skip_commit "$@";
else
git commit-tree "$@";
fi' HEAD
where the function skip_commit
is defined as follows:
skip_commit()
{
shift;
while [ -n "$1" ];
do
shift;
map "$1";
shift;
done;
}
But, as always when changing the history of your repo: if someone pulled from the repo before you modify it, he'll be in trouble.
Yes, you can do this with git filter-branch
but you'll have to consider the implications by doing this. Especially when other commits are based on the commits of the user that has to be removed.
When there are only few commits that have to be filtered, then you should use cherry pick and rebase.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With