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

编程入门 行业动态 更新时间:2024-10-24 23:19:46

Git 修改已提交的<a href=https://www.elefans.com/category/jswz/34/1770444.html style=用户名和邮箱"/>

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

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

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

git commit --amend --author 'Name<email>'

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

  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" = "这里写你原来的邮箱" ]
thencn="你想替换成的用户名"cm="你想替换成的邮箱"
fi
if [ "$GIT_AUTHOR_EMAIL" = "这里写你原来的邮箱" ]
thenan="你想替换成的用户名"am="你想替换成的邮箱"
fiexport GIT_AUTHOR_NAME="$an"export GIT_AUTHOR_EMAIL="$am"export GIT_COMMITTER_NAME="$cn"export GIT_COMMITTER_EMAIL="$cm"
'
  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"thenGIT_AUTHOR_EMAIL=john@examplefiif test "$GIT_COMMITTER_EMAIL" = "root@localhost"thenGIT_COMMITTER_EMAIL=john@examplefi
' -- --all

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

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

git filter-branch ... C..H

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

Author & Commiter

Author:

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

Commiter:

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

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

参考

参考了以下链接,在此做了一个更新和总结,感谢各位:
/

更多推荐

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

本文发布于:2023-12-05 02:48:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1662828.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:用户名   邮箱   Git

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!