为不同的存储库设置不同的配置 [英] Setting different config for different repositories

查看:47
本文介绍了为不同的存储库设置不同的配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何更改命令git config --list的内容?我要从 GitHub 提取/分叉存储库.我将在Windows,Linux和Mac工作站上配置此类存储库.

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.

推荐答案

如果要设置特定于特定存储库的配置,则有两种选择,可以从命令行进行配置,也可以编辑仓库的配置文件在编辑器中.

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.

只需使用命令行cd到Git存储库的根目录,然后运行git config --system--global标志,分别用于配置计算机和用户Git设置:

Simply use the command line, cd into the root of your Git repo, and run git config, without the --system and the --global flags, which are for configuring your machine and user Git settings, respectively:

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

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

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

Option 2: Edit config file directly

Your other option is to edit the repo config file directly. With a default Git clone, it's usually the .git/config file 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.

您可以在官方网站上了解有关配置Git的更多信息. git config 的Linux Kernel 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

编辑

解决原始海报有关如何更改的问题每个存储库中的user.nameuser.email ,这是通过命令行进行操作的方法.切换到每个存储库,然后运行以下命令:

Edit

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

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

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

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

这篇关于为不同的存储库设置不同的配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆