Git 作者未知

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8283915/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 12:24:49  来源:igfitidea点击:

Git author Unknown

gitgithub

提问by Alex Borsody

my author name in all my commits is coming up as unknownhttps://github.com/freeenergy/Teacher-Login-Validation-Module

我所有提交中的作者姓名都为未知https://github.com/freeenergy/Teacher-Login-Validation-Module

did this

做过这个

$ git config --global user.name "Firstname Lastname"Sets the name of the user for all git instances on the system
$ git config --global user.email "[email protected]"

but still the author/committer name shows [unknown]

但作者/提交者名称仍然显示 [未知]

not knowing what I was doing I experimented with setting $ GIT_AUTHOR_NAME="my name" and it changed my name to my username [freeenergy] (I.E. my issue was fixed.) But when I switched back to my other computer the issue was the same.

不知道我在做什么,我尝试设置 $ GIT_AUTHOR_NAME="my name" 并将我的名字更改为我的用户名 [freeenergy](即我的问题已解决。)但是当我切换回另一台计算机时,问题是一样的.

my config file now looks like this but is still committing as [unknown]

我的配置文件现在看起来像这样,但仍然以 [unknown] 的身份提交

[core]
    repositoryformatversion = 0
    filemode = false
    bare = false
    logallrefupdates = true
    symlinks = false
    ignorecase = true
    hideDotFiles = dotGitOnly
[remote "origin"]
    url = [email protected]:freeenergy/my-project.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[user]
    name = my name
    email = myEmail.com

回答by Bob Gilmore

Even better than running git config, you can edit your ~/.gitconfigfile directly. Look and see if there's a section for [user]with the relevant information. For example, my ~/.gitconfighas this...

甚至比运行更好git config,您可以~/.gitconfig直接编辑文件。查看并查看是否有[user]包含相关信息的部分。例如,我~/.gitconfig有这个...

[user]
    name = Bob Gilmore
    email = [email protected]

(There's no space in front of the [user], and single tabs in front of the name and email labels)

[user]名称和电子邮件标签前面没有空格,和单个选项卡)

If it doesn't have those set properly, just go ahead and edit the .gitconfig file by hand.

如果没有正确设置这些设置,请继续手动编辑 .gitconfig 文件。

回答by Ethan Mick

I was having the issue of Github not properly linking my commits to my account. If you believe your email is correct, you should ensure that email is alsoin the Github settings for your account, as per this help page. The last section of caching is also good to note.

我遇到了 Github 没有正确将我的提交链接到我的帐户的问题。如果您认为您的电子邮件是正确的,则应确保该电子邮件也在您帐户的 Github 设置中,如此帮助页面所述。缓存的最后一部分也值得一提。

Copied in case of a catastrophic event in which Github goes down or ceases to exist.

在 Github 宕机或不复存在的灾难性事件中复制。

Why are my commits linked to the wrong user?

为什么我的提交链接到错误的用户?

GitHub uses the email saved in a commit's header to link the commit to a GitHub user. If you find your commits are being blamed on another user, or not linked to a user at all, you should check your settings.

GitHub 使用保存在提交标题中的电子邮件将提交链接到 GitHub 用户。如果你发现你的提交被归咎于另一个用户,或者根本没有链接到用户,你应该检查你的设置。

Good to know:commit blame does not grant access to a repo. If you are seeing commits blamed on a user you do not know, don't worry. The user does not have access to your repo unless you've explicitly added them as a collaborator on that repo or to a team that has access to the repo.

很高兴知道:commit blame 不会授予对 repo 的访问权限。如果您看到提交归咎于您不认识的用户,请不要担心。用户无权访问您的存储库,除非您已明确将他们添加为该存储库的协作者或有权访问该存储库的团队。

Make them match

使它们匹配

In order for GitHub to properly blame you for your commits, make sure your git email setting is correct and matches an email attached to your account.

为了让 GitHub 正确地将您的提交归咎于您,请确保您的 git 电子邮件设置正确且与附加到您帐户的电子邮件相匹配。

Configuring git

配置git

To check your git setting, run this command:

要检查您的 git 设置,请运行以下命令:

$ git config user.email
# [email protected]

If this email is not correct, you can change the global setting:

如果此电子邮件不正确,您可以更改全局设置:

$ git config --global user.email "[email protected]"

Good to know:if you work on multiple machines, you will need to check this setting on each one.

很高兴知道:如果您在多台机器上工作,则需要在每台机器上检查此设置。

Attach the email to your GitHub account

将电子邮件附加到您的 GitHub 帐户

If your email is not attached to your GitHub account you will need to add it for your future commits to be blamed correctly.

如果您的电子邮件未附加到您的 GitHub 帐户,您将需要添加它,以便正确归咎于您未来的提交。

  1. Go to your Account Settings
  2. Click "Emails"
  3. Click "Add another email address"
  4. Enter the email address and click "Add"
  1. 转到您的帐户设置
  2. 点击“电子邮件”
  3. 点击“添加另一个电子邮件地址”
  4. 输入电子邮件地址,然后单击“添加”

The past is history

过去就是历史

If you used an invalid email, or an email that's already attached to another account, then your previous commits will not be blamed correctly. While git does allow you to modify the repo's history and correct this, it is strongly discouraged to change commits which you've pushed to a remote repo.

如果您使用了无效的电子邮件,或已附加到另一个帐户的电子邮件,那么您之前的提交将不会被正确归咎于。虽然 git 确实允许您修改 repo 的历史记录并更正这一点,但强烈建议您更改已推送到远程 repo 的提交。

In the case where your previous commits used the correct email, after you add the email to your account they will start to link. However, it may take some time for the old data to fall out of the server's cache before this happens.

如果您之前的提交使用了正确的电子邮件,则在您将电子邮件添加到您的帐户后,它们将开始链接。但是,在发生这种情况之前,旧数据可能需要一些时间才能从服务器的缓存中消失。

Moving forward, if your settings match then all your new commits will be blamed on you and linked to your account.

展望未来,如果您的设置匹配,那么您所有的新提交都将归咎于您并链接到您的帐户。

回答by Ania

I had to change the repository config file. Run from repository path :

我不得不更改存储库配置文件。从存储库路径运行:

> git config --local -e 

and add the whole section :

并添加整个部分:

[user]
    name = Anna Kowalska
    email = [email protected]

回答by Mene

In case you did already push your commits with a wrong user, you can rewrite the history using this script from github:

如果您已经使用错误的用户推送了您的提交,您可以使用来自 github 的脚本重写历史记录:

#!/bin/sh

git filter-branch --env-filter '
OLD_EMAIL="[email protected]"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="[email protected]"
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

Be awareof the effects a history rewrite has! If you are on a private branch you will propably be fine. On branches that are shared with other users you will need to coordinate with every other user and do a fetch on each clone. You need to decide if it's worth the effort. Have a backup!

请注意历史重写的影响!如果您在私人分支机构,您可能会没事。在与其他用户共享的分支上,您需要与每个其他用户协调并对每个克隆进行提取。您需要决定是否值得付出努力。有备份!

回答by WesternGun

I just found my recent push is with author "Unknown".

我刚刚发现我最近的推送是与作者“未知”。

What I just did was to reset the last commit by git reset --mixed HEAD~1and add, commit, and push -fby git-bash. Push by GitKraken always mess this up, but git-bashdoes it well. My suggestion is always check the author before push with git log.

我只是做了重置上次提交git reset --mixed HEAD~1addcommitpush -f通过git-bash。GitKraken 的推送总是搞砸了,但git-bash做得很好。我的建议是在使用git log.