V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
git
Pro Git
Atlassian Git Tutorial
Pro Git 简体中文翻译
GitX
lixyz
V2EX  ›  git

已经 push 到远程仓库的提交,如何修改某个用户的所有提交的邮箱啊

  •  
  •   lixyz · Oct 31, 2025 · 4637 views
    This topic created in 185 days ago, the information mentioned may be changed or developed.

    新换了老板,查看报表时候,发现我以往的 commit 邮箱不是公司邮箱

    我也比较纳闷。。。我记得我还专门设置过,排查下来,可能是 git 工具把我登录的账号默认的 git 配置给覆盖了

    现在问题来了,该如何把已经 push 到远程仓库的所有有关我的 commit 的邮箱全部修改啊

    求教大佬

    16 replies    2025-11-03 11:09:58 +08:00
    maichael
        1
    maichael  
       Oct 31, 2025   ❤️ 1
    git-filter-repo 之类的工具,具体用法你问 AI 就好,不过肯定是要 force push 的,谨慎操作。
    dif
        2
    dif  
       Oct 31, 2025
    git filter-branch 试试

    小声 bb ,不都看你需求单和缺陷工单么?怎么会看提交呢- - 我这修改一个小功能提交一次,那不得预定优秀员工?
    lixyz
        3
    lixyz  
    OP
       Oct 31, 2025
    @maichael force push 是肯定的,已经有心理预期了,很苦恼
    @dif 可说呢。。。报表统计代码行数。。。

    我试一下二位说的,先拿个测试仓库测试一下子,多谢多谢
    victimsss
        4
    victimsss  
       Oct 31, 2025
    commit hash 包括提交者信息和时间吧 你用工具修改了邮箱 之前的 commit hash 也会重写 对整个仓库的提交者都有影响
    skiy
        5
    skiy  
       Oct 31, 2025
    # 修改 author 信息
    git filter-repo --commit-callback '
    if commit.author_email == b"[email protected]":
    commit.author_name = b"New Name"
    commit.author_email = b"[email protected]"
    ' --force

    # 修改 committer 信息
    git filter-repo --commit-callback '
    if commit.committer_email == b"[email protected]":
    commit.committer_name= b"New Name"
    commit.committer_email = b"[email protected]"
    ' --force

    # 修改全部
    git filter-repo --force --commit-callback '
    if commit.committer_email == b"[email protected]":
    commit.author_name = b"New Name"
    commit.author_email = b"[email protected]"
    commit.committer_name = b"New Name"
    commit.committer_email = b"[email protected]"
    '

    git filter-repo --force --commit-callback '
    if commit.committer_email != b"[email protected]":
    commit.author_name = b"New Name"
    commit.author_email = b"[email protected]"
    commit.committer_name = b"New Name"
    commit.committer_email = b"[email protected]"
    '

    git filter-repo --force --commit-callback '
    commit.author_name = b"New Name"
    commit.author_email = b"[email protected]"
    commit.committer_name = b"New Name"
    commit.committer_email = b"[email protected]"
    '

    filter-repo 这个工具,能保持历史时间不变。还有一种是不用任何扩展也能改,但那个时间会切换成当前时间。
    icyalala
        6
    icyalala  
       Oct 31, 2025
    如果只是为了统计代码行数,那分邮箱统计出来后,再按单用户多邮箱合并一下不就行了
    为什么要去改 git 历史呢。。。
    lixyz
        7
    lixyz  
    OP
       Oct 31, 2025
    @icyalala 可能是公司的统计工具,只支持公司内部邮箱吧,反正现在领导反馈能改的话最好改一下。。。无奈。。。
    mach9452
        8
    mach9452  
       Oct 31, 2025
    学会拒绝
    awsl2333
        9
    awsl2333  
       Oct 31, 2025
    只能 rebase + push -f 了
    svon
        10
    svon  
       Oct 31, 2025
    git filter-branch -f --env-filter '
    OLD_EMAIL="旧邮箱地址"
    CORRECT_NAME="新名称"
    CORRECT_EMAIL="新邮箱"
    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
    wenrouxiaozhu
        11
    wenrouxiaozhu  
       Oct 31, 2025
    还有注意`GIT_COMMIT_DATE`和`GIT_AUTHOR_DATE`
    wweir
        12
    wweir  
       Oct 31, 2025
    前段时间,我一句话让 claude code 给我改了
    unused
        13
    unused  
       Oct 31, 2025
    zzhaolei
        15
    zzhaolei  
       Nov 2, 2025
    那都合并到 main 了,也要让你 force push ?不怕出问题吗?

    公司没明确说的,我都是用自己的邮箱,懒得改
    smallparking
        16
    smallparking  
       Nov 3, 2025 via Android
    我的建议是别改 影响太大,利益太小
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1080 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 63ms · UTC 23:58 · PVG 07:58 · LAX 16:58 · JFK 19:58
    ♥ Do have faith in what you're doing.