Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to remove all the commits of a specific user?

Tags:

git

github

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 ?

like image 858
Succeed Stha Avatar asked Aug 17 '11 10:08

Succeed Stha


2 Answers

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.

like image 88
eckes Avatar answered Sep 23 '22 14:09

eckes


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.

like image 37
matthias.lukaszek Avatar answered Sep 23 '22 14:09

matthias.lukaszek