Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GIT commit as different user without email / or only email

Tags:

git

commit

People also ask

Can I use git without email?

Use GitHub Anonymous NoReply Email (recommended) If using github or even if you're not, this is a better option than setting no email.

Can you git commit without a message?

Git does not recommend to commit without any message. Git commit messages are necessary to look back and see the changes made during a particular commit. If everyone will just commit without any message, no one would ever know what changes a developer has done.

How do you commit to a different author?

Creates a new commit by the specified author. Use git commit -m <message> to create a new commit with the specified <message> . Use the --author option to change the <name> and <email> of the commit's author.


The minimal required author format, as hinted to in this SO answer, is

Name <email>

In your case, this means you want to write

git commit --author="Name <email>" -m "whatever"

Per Willem D'Haeseleer's comment, if you don't have an email address, you can use <>:

git commit --author="Name <>" -m "whatever"

As written on the git commit man page that you linked to, if you supply anything less than that, it's used as a search token to search through previous commits, looking for other commits by that author.


The specific format is:

git commit --author="John Doe <[email protected]>" -m "Impersonation is evil." 

The

standard A U Thor <[email protected]> format

Seems to be defined as followed: ( as far as i know, with absolutely no warranty )

A U Thor = required username

  • The separation of the characters probably indicates that spaces are allowed, it could also be resembling initials.
  • The username has to be followed by 1 space, extra spaces will be truncated

<[email protected]> = optional email address

  • Must always be between < > signs.
  • The email address format isn't validated, you can pretty much enter whatever you want
  • Optional, you can omit this explicitly by using <>

If you don't use this exact syntax, git will search through the existing commits and use the first commit that contains your provided string.

Examples:

  1. Only user name

    Omit the email address explicitly:

    git commit --author="John Doe <>" -m "Impersonation is evil."
    
  2. Only email

    Technically this isn't possible. You can however enter the email address as the username and explicitly omit the email address. This doesn't seem like it's very useful. I think it would make even more sense to extract the user name from the email address and then use that as the username. But if you have to:

    git commit --author="[email protected] <>" -m "Impersonation is evil." 
    

I ran in to this when trying to convert a repository from mercurial to git. I tested the commands on msysgit 1.7.10.


The --author option doesn't do the right thing for the purpose of not leaking information between your git personalities: It doesn't bypass reading the invoking user's configuration:

*** Please tell me who you are.

Run

  git config --global user.email "[email protected]"
  git config --global user.name "Your Name"

This does:

git -c user.name='A U Thor' -c [email protected] commit

For the purpose of separating work- and private git personalities, Git 2.13 supports directory specific configuration: You no longer need to wrap git and hack this yourself to get that.


Just supplement:

git commit --author="[email protected] " -m "Impersonation is evil."

In some cases the commit still fails and shows you the following message:

*** Please tell me who you are.

Run

git config --global user.email "[email protected]" git config --global user.name "Your Name"

to set your account's default identity. Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got xxxx)

So just run "git config", then "git commit"