Can I configure git so it does not guess user.email configuration settings?

后端 未结 5 1884
余生分开走
余生分开走 2021-02-14 14:39

On my system I don\'t have the user.email git configuration value set at the global level, on purpose. Instead, I configure it individually in each sandbox. This is

5条回答
  •  不知归路
    2021-02-14 15:43

    Use a pre-commit hook

    You can use a pre-commit hook to prompt you to setup your project-specfic email address. For example:

    #!/bin/sh
    
    email=`git config user.email`
    
    if ["$email" = ''] 
    then
        echo "you need to set your email for this project"
        exit 1
    fi
    

    This will cause committing without the appropriate config to fail:

    $ git commit -va
    you need to set your email for this project
    $
    

    Use git's template to make sure it's always present

    You can use git templates to make sure the hook is present in future repositories by default, by placing the hook in the templates folder:

    -> tree /usr/share/git-core/templates/
    /usr/share/git-core/templates/
    ├── branches
    ├── description
    ├── hooks
    │   ├── applypatch-msg.sample
    │   ├── commit-msg.sample
    │   ├── post-update.sample
    │   ├── pre-applypatch.sample
    │   ├── pre-commit.sample
    │   ├── prepare-commit-msg.sample
    │   ├── pre-rebase.sample
    │   └── update.sample
    └── info
        └── exclude
    

    The exact location of the templates folder may vary with OS/distribution.

    For existing repositories - either create/copy the hook into place or if the git-core templates folder has been updated run git init to create the new hook file.

提交回复
热议问题