Setting the Default Author Email for All Git Commits in VS Code

To clarify, I am not suggesting setting distinct emails for authors and committers, having multiple authors or committers, or configuring separate local and global settings. Essentially, my proposal is to transform the current setup into a new one where users with multiple emails can designate a primary one and link it to their name and email for all associated addresses by using “write to” in Git.

Question:

All of my
git commits
in vscode 1.15.0 show the incorrect author email, specifically “@localhost”. However, my correct committer
email address
is being utilized, which is git version 2.11.0 (Apple Git-81) on macOS 10.12.6. To provide context, my configuration details are as follows:

  1. I use ssh keys to clone and push to/from Github.
  2. The name assigned to the global variable is
    user.name
    and it refers to the legendary basketball player, Michael Jordan.
  3. The email address of the global user is set to [email protected].
  4. In addition to my cloned repository, I also locally configured the user email.
  5. I use a Mac and my username is “mj”, which means that my home directory can be found at “/Users/mj”.

Following my changes being committed through vscode, I run

git log --format=full

and observe the ensuing outcome.

commit 
Author: Michael Jordan 
Commit: Michael Jordan 
    This is my dummy commit message

It’s a strange situation where I’m both the author and committer, but only the email associated with the committer is accurate. The author’s email, on the other hand, appears to be incorrect and is displaying as “mj” on localhost for some unknown reason. However, the author’s name, “Michael Jordan,” is being pulled from the git user.name settings.

I know I can fix this easily with

git commit --amend --author "Michael Jordan "

Nevertheless, carrying out this task through VS Code after each commit is not exactly convenient.

Is there a way to permanently resolve the problem with commits made through vscode, across all repositories? It should be noted that I do not encounter this problem when using Eclipse/egit, presumably because it utilizes the user.name and user.email settings.

I know that

git commit -m "My commit message" .

The author name “Michael Jordan” is used in both the mentioned platforms, namely, the one I’m currently using and the vscode. I am in dire need of a configuration setting in vscode that can eliminate the necessity of hooks.

Any idea?


UPDATE 1:

On
Win 8.1
, I attempted the identical procedure using the latest x64 vscode 1.15.0 and git version 2.14.1, and it succeeded without issue. As anticipated, the author is identical to the committer in this case.


Michael Jordan <[email protected]>

Following the installation of git version 2.14.1 on my Mac, I attempted to use it, only to find that it did not work due to an incorrect author email. Despite cloning the git repository from GitHub in both cases, the only discernible difference is that I have configured ssh keys for GitHub on my Mac, which I lack on my Win 8.1 machine.


Solution:

Check out what I stumbled upon in my .bash_profile:

...
export GIT_AUTHOR_NAME="Michael Jordan"
export GIT_AUTHOR_EMAIL="mj@localhost"
...

This is replacing the values of user.name and user.email.

My fault 🙁

Frequently Asked Questions

Posted in Git