• Git 修改已提交的用户名和邮箱


    Git 修改已提交的用户名和邮箱

    修改上一次提交的邮箱和用户名

    git commit --amend --author 'Name'
    
    • 1

    批量修改多次提交的邮箱和用户名

    1. 新建一个 .sh 脚本在 git 根目录下
    2. .sh脚本内容如下
    git filter-branch --env-filter '
    an="$GIT_AUTHOR_NAME"
    am="$GIT_AUTHOR_EMAIL"
    cn="$GIT_COMMITTER_NAME"
    cm="$GIT_COMMITTER_EMAIL"
    if [ "$GIT_COMMITTER_EMAIL" = "这里写你原来的邮箱" ]
    then
    	cn="你想替换成的用户名"
    	cm="你想替换成的邮箱"
    fi
    if [ "$GIT_AUTHOR_EMAIL" = "这里写你原来的邮箱" ]
    then
    	an="你想替换成的用户名"
    	am="你想替换成的邮箱"
    fi
    	export GIT_AUTHOR_NAME="$an"
    	export GIT_AUTHOR_EMAIL="$am"
    	export GIT_COMMITTER_NAME="$cn"
    	export GIT_COMMITTER_EMAIL="$cm"
    '
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    1. git 根目录下运行即可

    修改指定提交

    上述脚本中实现了在所有的提交中的修改,如果需要修改指定提交的用户名和邮箱,则需要:
    利用指令git rebase -i中的rewordrebase暂停,然后与指令git commit --amend配合,修改用户名和邮箱

    Note

    The --env-filter option can be used to modify committer and/or author identity. For example, if you found out that your commits have the wrong identity due to a misconfigured user.email, you can make a correction, before publishing the project, like this:

    git filter-branch --env-filter '
    	if test "$GIT_AUTHOR_EMAIL" = "root@localhost"
    	then
    		GIT_AUTHOR_EMAIL=john@example.com
    	fi
    	if test "$GIT_COMMITTER_EMAIL" = "root@localhost"
    	then
    		GIT_COMMITTER_EMAIL=john@example.com
    	fi
    ' -- --all
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    To restrict rewriting to only part of the history, specify a revision range in addition to the new branch name. The new branch name will point to the top-most revision that a git rev-list of this range will print.

    Consider this history:

         D--E--F--G--H
        /     /
    A--B-----C
    
    • 1
    • 2
    • 3

    To rewrite only commits D,E,F,G,H, but leave A, B and C alone, use:

    git filter-branch ... C..H
    
    • 1

    To rewrite commits E,F,G,H, use one of these:

    git filter-branch ... C..H --not D
    git filter-branch ... D..H --not C
    
    • 1
    • 2

    Author & Commiter

    Author:

    git log中的实际编写代码的人,换句话说就是提交log到本地仓库的人。

    Commiter:

    为将本地仓库push到远端仓库的人

    通常情况下 Author 与 Commiter 为同一个人,但是特殊情况下(网络异常…),比如 Author 无法将代码提交到远端仓库,所以请 Commiter 帮忙push到远端仓库

    参考

    参考了以下链接,在此做了一个更新和总结,感谢各位:
    https://hufangyun.com/2018/git-change-user-info/
    https://blog.csdn.net/weixin_30729609/article/details/96874653

  • 相关阅读:
    侦查帮派问题
    2019年1+X 证书 Web 前端开发中级理论考试题目原题+答案——第二套
    【一起来用C++】————(1)类的练习案例(多文件编写)
    6.5黄金行情分析
    java版工程管理系统Spring Cloud+Spring Boot+Mybatis实现工程管理系统源码
    Redis概述
    c++(六)
    【飞桨PaddleSpeech语音技术课程】— 一句话语音合成全流程实践
    写一篇nginx配置指南
    指令FTP/SFTP(有/无密码)连接、下载以及上传
  • 原文地址:https://blog.csdn.net/Ele_Dd/article/details/133978828