删除作者的所有提交 [英] Remove all commits by author

查看:57
本文介绍了删除作者的所有提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何删除某个作者的所有提交(错误提交-这样的作者在提交历史记录中不可见).

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="old@gmail.com"
CORRECT_NAME="name"
CORRECT_EMAIL="new@gmail.com"
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?

推荐答案

您可以这样做:

  1. 基于要开始的提交创建新分支:

  1. 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
    

  • log过滤出作者的所有提交,然后cherry-pick一个接一个地提交.

    The log filters out all commits made by the author and then cherry-picks them one after one.

    参数说明(部分引用自git log联机帮助页):

    Explanation for the parameters (partly quoted from git log manpage):

    • --author "name"
      将提交输出限制为具有与指定模式(正则表达式)匹配的作者/提交者标题行的提交.具有多个--author =的提交,其作者与给定的任何一个匹配 选择了模式(类似于多个--committer =).
    • --invert-grep
      将提交输出限制为带有与--grep =
    • 指定的模式不匹配的日志消息的提交
    • --reverse 以相反的顺序输出提交. […]
    • --format="format:%H" 使用自定义格式,在这种情况下,仅使用提交哈希
    • --author "name"
      Limit the commits output to ones with author/committer header lines that match the specified pattern (regular expression). With more than one --author=, commits whose author matches any of the given patterns are chosen (similarly for multiple --committer=).
    • --invert-grep
      Limit the commits output to ones with log message that do not match the pattern specified with --grep=
    • --reverse Output the commits in reverse order. […]
    • --format="format:%H" Use a custom format, in this case only the commit hash

    这篇关于删除作者的所有提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆