Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Commit without setting user.email and user.name

Tags:

git

I try to commit like this:

git commit --author='Paul Draper <[email protected]>' -m 'My commit message' 

but I get:

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

I can set these, but I am on a shared box, and I would have to (want to) unset them afterwards:

git config user.name 'Paul Draper' git config user.email '[email protected]' git commit -m 'My commit message' git config --unset user.name git config --unset user.email 

That's a lot of lines for one commit!

Is there shorter way?

like image 216
Paul Draper Avatar asked Feb 27 '14 02:02

Paul Draper


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 commit without adding?

Without adding any files, the command git commit won't work. Git only looks to the staging area to find out what to commit. Staging, or adding, files, is possible through the command line, and also possible with most Git interfaces like GitHub Desktop by selecting the lines or files that you'd like to stage.

What happens if you commit without 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.


1 Answers

(This occurred to me after suggesting the long version with the environment variables—git commit wants to set both an author and a committer, and --author only overrides the former.)

All git commands take -c arguments before the action verb to set temporary configuration data, so that's the perfect place for this:

git -c user.name='Paul Draper' -c user.email='[email protected]' commit -m '...' 

So in this case -c is part of the git command, not the commit subcommand.

like image 124
torek Avatar answered Sep 20 '22 16:09

torek