• 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

  • 相关阅读:
    Python生成词云
    Impedit odio facilis ad.Quinze également passer billet mensonge animer libre.
    A公司与B公司xx项目互通测试解决方案模板
    洛谷题单 Part2.2 排序算法(十种常见的排序算法)
    .NET 8 中的调试增强功能
    【leetcode】最近最少使用缓存
    使用 Node.js 和 Azure Function App 自动更新 Elasticsearch 索引
    Java:原型模式
    【javaEE】网络初识
    【C++进阶之路】第十一篇:C++的IO流
  • 原文地址:https://blog.csdn.net/Ele_Dd/article/details/133978828