git 为不同的存储库设置不同的配置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18181439/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 16:45:20  来源:igfitidea点击:

Setting different config for different repositories

gitgithub

提问by David B

I was wondering how am I going to change the contents of the command git config --list? I am going to pull/fork a repository from GitHub. I am going to configure such repositories on both of my Windows, Linux and Mac workstations.

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

回答by

If you want to set up configurations that are specific for a particular repository, you have two options, to configure it from the command line, or edit the repo's config file in an editor.

如果要设置特定于特定存储库的配置,您有两个选择,从命令行配置它,或在编辑器中编辑存储库的配置文件。

Option 1: Configure via command line

选项 1:通过命令行配置

Simply use the command line, cdinto the root of your Git repo, and run git config, withoutthe --systemand the --globalflags, which are for configuring your machine and user Git settings, respectively:

使用简单的命令行,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

选项2:直接编辑配置文件

Your other option is to edit the repo config file directly. With a default Git clone, it's usually the .git/configfile in your repo's root folder. Just open that file in an editor and starting adding your settings, or invoke an editor for it at the command line using git config --edit.

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

Resources

资源

You can learn more about configuring Git at the official Linux Kernel Git documentation for git config. In particular, you may be interested in seeing an example Git config:

您可以在官方 Linux 内核 Git 文档中git config了解有关配置 Git 的更多信息。特别是,您可能有兴趣查看示例 Git 配置

# 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

Edit

编辑

Addressing the original poster's question about how to change user.nameand user.emailper repository, here is how to do it via the command line. Switch to each repository, and run the following:

解决原始发布者关于如何更改user.nameuser.email每个存储库的问题,这里是如何通过命令行执行此操作。切换到每个存储库,并运行以下命令:

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

Since you're not using the --systemor the --globalflags, the above commands will apply to whichever repo you have in your terminal working directory only.

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