Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting user data just for one commit

Tags:

git

I don't have the git user data set:

$ git commit -m '...'

*** 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: empty ident name (for <...>) not allowed

If I run these commands my user data will be set globally. I only want to have the user data set for one commit.

Is there any argument that I can pass to git commit to set the user data?

like image 465
Ionică Bizău Avatar asked May 09 '26 16:05

Ionică Bizău


1 Answers

The --author flag will set the author, but you must also set the committer name and email.

There is no command-line flag for this but git will use environment variables if they are set: GIT_COMMITTER_NAME and GIT_COMMITTER_EMAIL.

Assuming an sh/bash-style shell:

GIT_COMMITTER_NAME='A U Thor' \
GIT_COMMITTER_EMAIL='[email protected]' \
git commit --author 'A U Thor <[email protected]>' ...

should do it.

Or, you can just set these in your git global configuration, then remove them (use git config --global -e to run your favorite editor on the file, if you don't want to fiddle with git config --unset).

Edit: or, you can configure them temporarily with git -c name=value, e.g.:

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

Note that (as with the environment variables) this will override any file-configuration values.

like image 156
torek Avatar answered May 11 '26 15:05

torek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!