如何使用 ssh 密钥更改 git commit 的作者

use*_*593 4 git git-filter-branch git-commit gitlab

我已经创建了 ssh 密钥并将其添加到我的 gitlab 帐户中。

然后,我做出了承诺:

git add .
git commit -m "w"
git push origin master
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述(https://prnt.sc/q7yc4q)

但正如你所看到的,我提交时的用户名是root(这是因为我笔记本电脑上的用户是root

  • 1)如何设置所需的用户名(让我们称之为)batman,这样我希望将batman显示为提交作者而不是root?

  • 2)我可以只使用 gitlab 界面来完成此操作,而不弄乱笔记本电脑上的 git 配置吗?(我这样问是因为我有几个 git 帐户,并且我需要为我的项目使用不同的帐户)

Cod*_*ard 7

如何设置所需的用户名(让我们称之为batman),这样我希望将batman 显示为提交作者而不是root?

为所有项目设置用户名/电子邮件

# Set the username for git commit
git config --global user.name "<your name>"

# Set the emailfor git commit
git config --global user.email "<your email address>"
Run Code Online (Sandbox Code Playgroud)

...我需要为我的项目使用不同的帐户

为单个项目设置用户名/电子邮件

# --local is the default so you don't have to add it

# Set the username for git commit
git config --local user.name="<your name>"

# Set the emailfor git commit
git config --local user.email="<your email address>"
Run Code Online (Sandbox Code Playgroud)

替换提交中错误的作者(将更新您用户的所有提交)

git filter-branch -f --env-filter '
    GIT_AUTHOR_NAME="Newname"
    GIT_AUTHOR_EMAIL="newemail"
    GIT_COMMITTER_NAME="Newname"
    GIT_COMMITTER_EMAIL="newemail"
  ' HEAD
Run Code Online (Sandbox Code Playgroud)

替换最新提交中错误的作者

# Update the username and email as explained above
# Re-commit to update the username/email
git commit --amend --no-edit 
Run Code Online (Sandbox Code Playgroud)

  • 我收到错误“错误:无效密钥:user.name=enix426”。通过删除“=”符号解决:user.name“&lt;您的名字&gt;” (3认同)