GIT commit as different user without email / or only email

Viewed 172393

I'm trying to commit some changes as a different user, but i do not have a valid email address, following command is not working for me:

git commit --author="john doe" -m "some fix"
fatal: No existing author found with 'john doe'

I have the same problem when trying to commit with only an email address

git commit --author="john@doe.com" -m "some fix"
fatal: No existing author found with 'john@doe.com'

On the GIT man pages for the commit command it says i can use the

standard A U Thor <author@example.com> format

For the --author option.

Where is this format defined ? what does A and U stand for ? how do i commit for a different user with only a username or only an email?

10 Answers

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 "you@example.com"
  git config --global user.name "Your Name"

This does:

git -c user.name='A U Thor' -c user.email=author@example.com 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.

Open Git Bash.

Set a Git username:

$ git config --global user.name "name family" Confirm that you have set the Git username correctly:

$ git config --global user.name

name family

Set a Git email:

$ git config --global user.email email@foo.com Confirm that you have set the Git email correctly:

$ git config --global user.email

email@foo.com

It is all dependent on how you commit.

For example:

git commit -am "Some message"

will use your ~\.gitconfig username. In other words, if you open that file you should see a line that looks like this:

[user]
    email = someemail@gmail.com

That would be the email you want to change. If your doing a pull request through Bitbucket or Github etc. you would be whoever you're logged in as.

git -c "user.name={{ name }}" -c "user.email={{ email }}" commit -m "{{ message }}"

where {{ }} indicates YOU put the value

Related