Succeed Stha
Succeed Stha

Reputation: 1747

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

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 ?

Upvotes: 9

Views: 1610

Answers (2)

eckes
eckes

Reputation: 67067

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.

Upvotes: 8

matthias.lukaszek
matthias.lukaszek

Reputation: 2220

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.

Upvotes: 2

Related Questions