我在试图将我的提交与GitHub账户连接时遇到了问题。GitHub上报告的提交方式如图片所示。值user.name和user.email是正确的,还有其他检查的想法吗?
提前感谢!
我在试图将我的提交与GitHub账户连接时遇到了问题。GitHub上报告的提交方式如图片所示。值user.name和user.email是正确的,还有其他检查的想法吗?
提前感谢!
user.email
字段中的某些内容不正确,这会给Github提供关于提交者的错误信息。一个小错误可能会导致整个过程失败。修复方法在第三步,前两步帮助识别问题所在。git config -l
检查您的设置,并确保其中没有意外的内容。运行git log
并注意Author
字段的样式。它应该是Author: 您的名字 <您的Github邮箱@example.com>
格式。括号内的部分是Github关注的重点。git log
找到一切正常工作的提交。将那个Author
字段与未正常工作的进行对比,看看是否有差异。git config --global user.email correct-email@example.com
。git config
命令设置global
标志,以更改所有存储库的相应设置(如果未被特定存储库设置覆盖),例如:git config --global user.email "test@example.com"
。对于user.name
和user.email
的更改仅适用于新提交。 - Dennis van der Schagtgit config -l
命令后,向输出的顶部看,你会看到 user.email=
。这可能是问题所在。你的电脑可能自动设置了一些东西。因此,请运行上面的 git config
命令,然后你就可以愉快地继续了 :) - Anthony Avila我有一个类似的问题,stvnrlly的回答很有用。 在我的情况下,运行以下命令:
git config --global user.email
在我的情况下,CL会输出"email@email.com"
,这是错误的,因为它应该显示没有""
的电子邮件地址。所以我认为设置并没有正确完成。
git config
设置。$ cd working_dir
$ git clone --bare https://github.com/user/repo.git
$ cd repo.git
Your commits might be unlinked to your original GitHub due to various reasons, i.e. incorrect/old email, incorrect/old username, etc. Also, your commit and/or authorship details might be incorrect. I list down different steps for different cases.
3.1 Incorrect email linked
If commit details are incorrect:
Paste the following code in your command line.
git filter-branch --env-filter '
OLD_EMAIL="old@email.com"
CORRECT_NAME="correct-username"
CORRECT_EMAIL="correct@email.com"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags
If author details are incorrect:
Paste the following code in your command line.
git filter-branch --env-filter '
OLD_EMAIL="old@email.com"
CORRECT_NAME="correct-username"
CORRECT_EMAIL="correct@email.com"
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
Here, replace OLD_EMAIL
with your old email address, CORRECT_NAME
with your current username, and CORRECT_EMAIL
with your current correct email address.
You can check your old email address(es) using the command: git log --pretty="format:%ae"
3.2. Wrong username linked
If commit details are incorrect:
Paste the following code in your command line.
git filter-branch --env-filter '
OLD_NAME="old-username"
CORRECT_NAME="correct-username"
CORRECT_EMAIL="correct@email.com"
if [ "$GIT_COMMITTER_NAME" = "$OLD_NAME" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags
If author details are incorrect:
Paste the following code in your command line.
git filter-branch --env-filter '
OLD_NAME="old-username"
CORRECT_NAME="correct-username"
CORRECT_EMAIL="correct@email.com"
if [ "$GIT_AUTHOR_NAME" = "$OLD_NAME" ]
then
export GIT_AUTHOR_NAME="$CORRECT_NAME"
export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags
Here, replace OLD_NAME
with your old name/username appearing on commits, CORRECT_NAME
with your current username, and CORRECT_EMAIL
with your current correct email address.
Your output should look something like this:
Rewrite c9ef481aca2cbeac930da8b1250c7f81ac779372 (19/20) (2 seconds passed, remaining 0 predicted)
Ref 'refs/heads/main' was rewritten
If your output looks like this, move to step 4.
Push the modified history to your original repository.
$ git push --force --tags origin 'refs/heads/*'
Username for 'https://github.com': user
Password for 'https://user@github.com':
Enumerating objects: 96, done.
Counting objects: 100% (96/96), done.
Delta compression using up to 40 threads
Compressing objects: 100% (48/48), done.
Writing objects: 100% (94/94), 852.67 KiB | 42.63 MiB/s, done.
Total 94 (delta 41), reused 77 (delta 40)
remote: Resolving deltas: 100% (41/41), done.
To https://github.com/user/repo.git
+ 4777199...1f210c5 main -> main (forced update)
$ cd ..
$ rm -rf repo.git
user.email
:这里填写您创建账户或当前链接到账户的电子邮件地址。不是xyz@github.com
,而是xyz@gmail.com
user.name
| user.username
:您需要两者,两者的值应该相同。它在您的账户 URL、个人资料等处都可以找到。
如何设置这些值:
git config --global user.email "xyz@gmail.com"
git config --global user.name xyz
git config --global user.username xyz
检查这些值是否已设置:
git config --global --list
我刚刚将我的工作邮箱添加到了GitHub的备用邮箱中
首先,您需要获取远程存储库的引用。
git remote add origin https://github.com/yourGithubAccount/yourRepo.git
然后执行git push -u origin master
命令。
git remote -v
并报告它的样子(git协议)。 - Dennis van der Schagt