开发者

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

开发者 https://www.devze.com 2023-03-28 12:21 出处:网络
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 remov

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消