Commit without setting user.email and user.name

后端 未结 3 2038
心在旅途
心在旅途 2020-12-07 16:21

I try to commit like this

git commit --author=\'Paul Draper \' -m \'My commit message\'

but I get

***          


        
相关标签:
3条回答
  • 2020-12-07 16:44

    It is worth noting, that git on linux will default to the linux user name as given in the "gecos" field in /etc/passwd. You can output this name with grep $(whoami) /etc/passwd | cut -d ':' -f 5. If this field is empty you cannot commit without setting a user name but if it is not empty git will use it. So you'd have yourself as author and the system user as committer.

    See https://github.com/git/git/blob/master/ident.c

    0 讨论(0)
  • 2020-12-07 17:01

    (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='my@email.org' commit -m '...'
    

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

    0 讨论(0)
  • 2020-12-07 17:02

    You can edit the .git/config file in your repo to add the following alias :

    [alias]
      paulcommit = -c user.name='Paul Draper' -c user.email='my@email.org' commit
    

    or you can do this by command line :

    git config alias.paulcommit "-c user.name='Paul Draper' -c user.email='my@email.org' commit"
    

    And then you can do :

    git paulcommit -m "..."
    

    Remarks:

    • The idea is then to add also aliases like jeancommit, georgecommit, ... for the other users of this shared box.
    • You can add this alias to your global config by editing your personal .gitconfig or by adding --global option to the command line when adding the alias.
    • The alias paulcommit is not a short one, but it is verbose and you can in general type only git pau+tab.
    0 讨论(0)
提交回复
热议问题