特定存储库的 Git 全局配置?

标签 git

意思是,有类似每个 repo 部分 [repo_url] 的东西覆盖全局(不是特定 repo )选项。

[core]
    filemode = false
    editor = notepad
[repo "example.com/repo1.git"]
    [core]
        filemode = true
        # editor = notepad
[repo "example.com/repo2.git"]
    [core]
        editor = vim
        # filemode = false

在 git 中可以吗?

注意:我正在制作大量的 repos 克隆(git clone),我会在这样的全局配置中指定

最佳答案

有了 Git 2.36(2022 年第 2 季度),除了依赖本地文件夹之外,您还有另一种选择:使用“[includeIf <condition>]”的配置文件的条件包含机制学会根据URL 存储库与之交互的远程存储库。

参见 commit 399b198 , commit ed69e11 (2022 年 1 月 18 日)Jonathan Tan ( jhowtan ) .
(由 Junio C Hamano -- gitster -- merge 于 commit 13ce8f9 ,2022 年 2 月 9 日)

config: include file if remote URL matches a glob

Signed-off-by: Jonathan Tan
Acked-by: Elijah Newren

This is a feature that supports config file inclusion conditional on whether the repo has a remote with a URL that matches a glob.

Similar to my previous work on remote-suggested hooks, the main motivation is to allow remote repo administrators to provide recommended configs in a way that can be consumed more easily (e.g. through a package installable by a package manager - it could, for example, contain a file to be included conditionally and a post-install script that adds the include directive to the system-wide config file).

In order to do this, Git reruns the config parsing mechanism upon noticing the first URL-conditional include in order to find all remote URLs, and these remote URLs are then used to determine if that first and all subsequent includes are executed.
Remote URLs are not allowed to be configured in any URL-conditionally-included file.

config现在包含在其 man page 中:

hasconfig:remote.*.url:

The data that follows this keyword is taken to be a pattern with standard globbing wildcards and two additional ones, **/ and /**, that can match multiple components.
The first time this keyword is seen, the rest of the config files will be scanned for remote URLs (without applying any values).
If there exists at least one remote URL that matches this pattern, the include condition is met.

Files included by this option (directly or indirectly) are not allowed to contain remote URLs.

Note that unlike other includeIf conditions, resolving this condition relies on information that is not yet known at the point of reading the condition.

A typical use case is this option being present as a system-level or global-level config, and the remote URL being in a local-level config; hence the need to scan ahead when resolving this condition.

In order to avoid the chicken-and-egg problem in which potentially-included files can affect whether such files are potentially included, Git breaks the cycle by prohibiting these files from affecting the resolution of these conditions (thus, prohibiting them from declaring remote URLs).

As for the naming of this keyword, it is for forwards compatibility with a naming scheme that supports more variable-based include conditions, but currently Git only supports the exact keyword described above.

config现在包含在其 man page 中:

; include only if a remote with the given URL exists (note
; that such a URL may be provided later in a file or in a
; file read after this file is read, as seen in this example)
[includeIf "hasconfig:remote.*.url:https://example.com/**"]
path = foo.inc
[remote "origin"]
url = https://example.com/git

关于特定存储库的 Git 全局配置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61983894/

相关文章:

git:你的分支和 'origin/master' 有分歧 - 如何丢弃本地提交?

git - Bitbucket 符号(箭头)含义

git - Git 来回 merge 后,为什么分支不在同一点?

git - 是否可以自定义 .gitignore?只读权限?

git:仅重做旧提交

git - 如何在gitolite中安装钩子(Hook)

git - 使用 hg Convert 将 git repo 转换为旧的 svn 格式

git - 是否可以维护两个具有完全不同内容的本地Git存储库,但将它们推送到同一远程存储库?

windows - 无法启动 Git Bash

git - 一分为二,从最初的提交