1

I am currently in a SWE class in which we all work on a project in one single Github repository.

We get graded largely from a script that goes through our commits to the repository, but I unfortunately did not realize that I did not have my email and username configured in my terminal for Git and as a result all of the code that I pushed up to our repository is not associated with my Github account.

The professor has a script that analyzes these commits and assigns a grade based on what the script spits out, but since I didn't have my email/username configured in my terminal this script will not catch my commits.

Is there any way to fix this?
I found this article, but I don't think the script will work since there is no email associated with these commits. Thanks in advance.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
ddipi
  • 13
  • 2
  • 1
    Git requires some kind of name and email to be configured or it won't let you commit. So my guess is that your commits are associated with a different email address than your GitHub account. If you do `git show ` where `` is the ID (the SHA1) of a commit you wrote, what email does it show in the output? If you can add that email to your GitHub account, it will make the commits show up with your username, which might solve the problem. – drmercer Apr 02 '20 at 14:39
  • This fixed it, thank you so much! – ddipi Apr 02 '20 at 21:11
  • Glad to hear! :) – drmercer Apr 03 '20 at 03:09

1 Answers1

2

It will be problematic if everybody has pushed to the same branch, because rewriting your local history with right username/email will imply a git push --force, meaning that will change the SHA1 of commits on the remote repository side.

If you have push in a separate branch however, you can force push without much consequence beside alerting the professor and make sure the script will consider your newly written branch.

Check if there is really no email associated to your last commit with:

git log --format='%ae' HEAD

The OP ddipi confirm in the comments:

I used the git log --format='%ae' HEAD command to find out that I actually was using my old email address.
I added it to my Github account and the problem was solved.


For resetting user/email on commits, I would recommend this days to use the new tool git filter-repo, which replaces BFG and git filter-branch.
See its user manual.

To modify username and emails of commits, you can create a mailmap file in the format accepted by git-shortlog.
For example, if you have a file named my-mailmap you can run

git filter-repo --mailmap my-mailmap

and if the current contents of that file are as follows (if the specified mailmap file is version controlled, historical versions of the file are ignored):

Correct Name <correct@email.com> <old@email.com>

then we can update username and/or emails based on the specified mapping.

See git shortlog "mapping author" section for the exact syntax of a mailmap file.

Or, with callbacks:

git-filter-repo --name-callback 'return name.replace(b"OldName", b"NewName")' \
   --email-callback 'return email.replace(b"old@email.com", b"new@email.com")'
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I used the `git log --format='%ae' HEAD` command to find out that I actually was using my old email address. I added it to my Github account and the problem was solved. Thanks! – ddipi Apr 02 '20 at 21:10
  • @ddipi Great! I have included your comment in the answer for more visibility. – VonC Apr 03 '20 at 04:10