1

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:

enter image description here

After git log I see this:

enter image description here

It's all mixed up.

In the repository the name is not correct.

Nicolás Alarcón Rapela
  • 2,714
  • 1
  • 18
  • 29
Usr
  • 2,628
  • 10
  • 51
  • 91

1 Answers1

4

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

torek
  • 448,244
  • 59
  • 642
  • 775
  • Hi, I've tried this solution earlier by running the script, but it didn't work either. – Usr Feb 12 '19 at 10:17
  • When you use `git show` locally, what author/committer information do you see? What hash ID do you see? What hash ID do you see after `git push`? For that matter, how are you viewing the commits in the other, non-local Git repository? – torek Feb 12 '19 at 10:19
  • After git show the author appears as "MyNewName ", so it's a mix of the two. Where can I see the hasID? – Usr Feb 12 '19 at 10:21
  • `git show` and `git log` print the hash ID at the front of the whole thing. If you're seeing the right name but the wrong email address, something has gone wrong with the spelling of `GIT_AUTHOR_EMAIL` and/or `GIT_COMMITTER_EMAIL`. – torek Feb 12 '19 at 10:22
  • Or that @MLondei didn't configure the new email with `git config --global user.email ` [Link](https://help.github.com/articles/setting-your-commit-email-address-in-git/) – clamentjohn Feb 12 '19 at 10:25
  • I've edited the question. @clmno I've already configured the email with that command. – Usr Feb 12 '19 at 10:26
  • @clmno: I'm assuming here that he is using the GitHub script or similar. Note also that `git config --global user.email name@host` won't override an accidental wrong `git config user.email name@host` (local)! – torek Feb 12 '19 at 10:26
  • OK, a quick diagnostic might help: *new* commits will acquire whatever `git config --get user.name` and `git config --get user.email` show, so if those show the right thing, you're all set for *new* commits. We'll just need to fix the existing commits (via copying). The image shows that the existing commits have two different email addresses. It's also a bit suspicious that there are *four* commits showing locally, but only three on GitHub... – torek Feb 12 '19 at 10:31
  • 1
    The filter-branch recipes on both GitHub and the linked question work by email address. I'm not sure which one is the one to be considered "wrong" here but you would select that one as the commits to match for the copy-and-replace process. Once you've done the copy-and-replace, `git log` locally should show the correct name-and-email, with new/different commit hash IDs. You must then do the `git push --force` operation to send those to GitHub. Note that GitHub's author statistics are updated on a delay, so some things may not show up for a while. – torek Feb 12 '19 at 10:35