为不同的存储库设置不同的配置[重复]

问题描述 投票:20回答:1

这个问题在这里已有答案:

我想知道如何更改命令git config --list的内容?我将从GitHub拉/存储库。我将在我的Windows,Linux和Mac工作站上配置这样的存储库。

git github
1个回答
48
投票

如果要设置特定于特定存储库的配置,可以使用两个选项,从命令行进行配置,或在编辑器中编辑repo的配置文件。

Option 1: Configure via command line

只需将命令行cd用于Git仓库的根目录,然后运行git config,而不使用--system--global标志,分别用于配置机器和用户Git设置:

cd <your-repo>
git config <setting-name> <setting-value>
git config <setting-name>=<setting-value> # alternate syntax

Option 2: Edit config file directly

您的另一个选择是直接编辑repo配置文件。使用默认的Git克隆,它通常是repo的根文件夹中的.git/config文件。只需在编辑器中打开该文件并开始添加设置,或使用git config --edit在命令行中为其调用编辑器。

Resources

您可以在official Linux Kernel Git documentation for git config上了解有关配置Git的更多信息。特别是,您可能有兴趣看到example Git config

# Core variables
[core]
        ; Don't trust file modes
        filemode = false
# Our diff algorithm
[diff]
        external = /usr/local/bin/diff-wrapper
        renames = true
[branch "devel"]
        remote = origin
        merge = refs/heads/devel
# Proxy settings
[core]
        gitProxy="ssh" for "kernel.org"
        gitProxy=default-proxy ; for the rest
[include]
        path = /path/to/foo.inc ; include by absolute path
        path = foo ; expand "foo" relative to the current file
        path = ~/foo ; expand "foo" in your $HOME directory

编辑

解决original poster's question about how to change user.name and user.email per repository问题,这是如何通过命令行完成的。切换到每个存储库,然后运行以下命令:

git config user.name "<name>"
git config user.email "<email>"

由于您没有使用--system--global标志,因此上述命令仅适用于终端工作目录中的任何repo。

© www.soinside.com 2019 - 2024. All rights reserved.