Git push继续使用错误的用户名编写提交 [英] Git push keeps writing commit with wrong username

查看:97
本文介绍了Git push继续使用错误的用户名编写提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在共享计算机上创建了一个新项目,并且我的存储库中的提交使用了错误的Git用户名.我已在Windows的凭据管理器中更改了凭据,并遵循了此指南,但是即使我按要求输入用户名和密码,作者也没有改变,我插入了我的.不过,在存储库中,提交的作者不是我.我也尝试过此解决方案,但仍然无法正常工作. >

我还能尝试什么?

更新

步骤:
-git commit -m "message"
-git push origin master

然后要求输入电子邮件和密码.我插入我的它,它可以正确推送,然后我进入存储库并看到以下内容:

在git log之后,我看到了:

这一切都混了.

在存储库中,名称不正确.

解决方案

您正在错误的前提下进行工作,因此您无法解决此问题,除非您更改方法:git push转移现有提交从一个存储库到另一个存储库.传输过程使用您的凭据(来自https://的管理者的凭据,或ssh://的存储的ssh凭据),但是 commits 已被冻结:它们具有为其作者设置的任何名称和提交者,并且这些不能更改.

因此,您需要进行新的和不同的提交.进行提交时,Git在此处使用的名称和电子邮件地址不是您在任何凭据中设置的不是数据,也不存储在任何ssh密钥中.相反,它们仅使用您的user.nameuser.email设置.

如果您有现有的提交,可以将它们复制到与原始文件完全相同但又稍有不同的新改进的提交中:

  • 具有不同的作者和提交者名称(您的新的和改进的,更正的名称),并且

  • 具有不同的哈希ID(因为它们是不同的提交).

然后您可以告诉Git:丢弃那些棘手的旧提交,而改用我闪亮的新提交.您将不再看到旧提交,而只会看到新提交.如果仔细观察,即使有关它们的所有 else 都是相同的,您也会看到新的具有新的哈希ID.

要执行此操作,请参见如何更改Git中多次提交的作者和提交者名称以及电子邮件? .请注意,您应该注意仅复制使用错误的名称和电子邮件地址设置所做的提交.链接的问题副本 any 上接受的答案与一个特定的电子邮件地址匹配,因此,如果您误用了Linus Torvalds的电子邮件地址,并在Linux系统上尝试使用,则会被替换他的所有承诺.但是在典型情况下,您的错误电子邮件是唯一的,您将仅替换您输入的错误的最后几次提交.

(注意:如果在您的问题中确切显示 您正在采取什么步骤以及 exact 的结果,这可能会有所帮助.例如,如果git push non-fast-forward失败,我们将更多地了解发生了什么事情.)

I've created a new project on a shared machine and the commits in my repositories are under the wrong username on Git. I've changed the credentials in the credentials manager in windows, I've followed this guide but the author has not changed, even if when I push it asks me username and password for pushing, and I insert mine. Still, on the repository the author of the commit is not me. I've also tried this solution but still doesn't work.

What else can I try?

UPDATE

Steps:
- git commit -m "message"
- git push origin master

Then it asks for email and password. I insert mine, it pushes correctly and then I go to the repository and see this:

After git log I see this:

It's all mixed up.

In the repository the name is not correct.

解决方案

You're laboring under a false premise, so you cannot fix this until you change your approach: git push transfers existing commits from one repository to another. The transfer process uses your credentials—the ones from the manager for https://, or the stored ssh ones for ssh://—but the commits are already frozen: they have whatever name is set for their author and committer, and these cannot be changed.

Therefore, you need to make new and different commits. When you make commits, the name and email address that Git uses here are not data you set in any credentials, nor stored in any ssh keys. Instead, these use only your user.name and user.email settings.

If you have existing commits that you like, you can copy them to new-and-improved commits that are almost exactly the same as the originals, but slightly different in that they:

  • have a different author and committer name (your new and improved, corrected ones), and

  • have different hash IDs (because they're different commits).

You can then tell your Git: Throw out those icky old commits and use my shiny new improved ones instead. You'll stop seeing the old commits and will see only the new ones. If you look closely, you will see that the new ones have new hash IDs, even though everything else about them is identical.

To do that, see How to change the author and committer name and e-mail of multiple commits in Git?. Note that you should be careful to copy only the commits you made using the wrong name-and-email-address setting. The accepted answer at the linked question copies any commits that match one particular email address, so if you mistakenly used, say, Linus Torvalds' email address and try this on a Linux system, you'll be replacing all of his commits. But in the typical case, where your wrong email was unique, you'll replace just the last few commits that you got wrong.

(Note: it may help if, in your question, you show exactly what steps you are taking and the exact results. For instance, if the git push is failing with non-fast-forward, we'll know more about what's going wrong.)

这篇关于Git push继续使用错误的用户名编写提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆