已经 push 到远程仓库的提交,如何修改某个用户的所有提交的邮箱啊 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
git
Pro Git
Atlassian Git Tutorial
Pro Git 简体中文翻译
GitX
/div>
lixyz
V2EX    git

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

  •  
  •   lixyz 17 小时 21 分钟前 1685 次点击

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

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

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

    求教大佬

    13 条回复    2025-10-31 16:29:38 +08:00
    maichael
        1
    maichael  
       17 小时 6 分钟前   1
    git-filter-repo 之类的工具,具体用法你问 AI 就好,不过肯定是要 force push 的,谨慎操作。
    dif
        2
    dif  
       17 小时 4 分钟前
    git filter-branch 试试

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

    我试一下二位说的,先拿个测试仓库测试一下子,多谢多谢
    victimsss
        4
    victimsss  
       16 小时 54 分钟前
    commit hash 包括提交者信息和时间吧 你用工具修改了邮箱 之前的 commit hash 也会重写 对整个仓库的提交者都有影响
    skiy
        5
    skiy  
       16 小时 52 分钟前
    # 修改 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  
       16 小时 50 分钟前
    如果只是为了统计代码行数,那分邮箱统计出来后,再按单用户多邮箱合并一下不就行了
    为什么要去改 git 历史呢。。。
    lixyz
        7
    lixyz  
    OP
       16 小时 48 分钟前
    @icyalala 可能是公司的统计工具,只支持公司内部邮箱吧,反正现在领导反馈能改的话最好改一下。。。无奈。。。
    mach9452
        8
    mach9452  
       16 小时 41 分钟前
    学会拒绝
    awsl2333
        9
    awsl2333  
       15 小时 37 分钟前
    只能 rebase + push -f 了
    svon
        10
    svon  
       14 小时 55 分钟前
    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  
       13 小时 49 分钟前
    还有注意`GIT_COMMIT_DATE`和`GIT_AUTHOR_DATE`
    wweir
        12
    wweir  
       12 小时 46 分钟前
    前段时间,我一句话让 claude code 给我改了
    unused
        13
    unused  
       12 小时 11 分钟前
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     868 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 21ms UTC 20:41 PVG 04:41 LAX 13:41 JFK 16:41
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86