简体   繁体   中英

Git push keeps writing commit with wrong username

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.)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM