【问题标题】:Default config settings for a new git repository?新 git 存储库的默认配置设置?
【发布时间】:2011-01-06 18:38:21
【问题描述】:

当我创建一个新的 git 存储库时,一些配置设置会自动添加到 .git/config。我在哪里可以更改这些默认设置?

【问题讨论】:

    标签: git configuration


    【解决方案1】:

    考虑git init的选项模板:

     --template=<template_directory>
    

    提供将使用模板的目录。默认模板目录为/usr/share/git-core/templates

    指定时,&lt;template_directory&gt; 用作模板文件的来源,而不是默认来源。
    模板文件包括一些目录结构、一些建议的“排除模式”和非执行“挂钩”文件的副本。建议的模式和挂钩文件都是可修改和可扩展的。

    如果您查看 creating a new db 的 git 源代码,您可以在其中包含一个带有默认值的配置文件。

    function create_default_files() 确实有:

     /* First copy the templates -- we might have the default
      * config file there, in which case we would want to read
      * from it after installing.
      */
    copy_templates(template_path);
    

    git/config.c 具有设置默认值的git_default_core_config() 函数。

    【讨论】:

    • @Jubobs 我已恢复链接。
    • 看代码,好像设置是自动确定的,无法更改。例如。我想更改 core.filemode 的默认设置,但这是基于检查 ("/* Check filemode trustabililty */") 的硬编码。
    • 我在[core] 部分添加了一个文件/usr/share/git-core/templates/config,其中filemode = false 和一个随机的xyz = fooxyz = foo 有效,但由于上面提到的硬编码逻辑,filemode = false 被覆盖。
    【解决方案2】:

    所有 git 全局配置都可以通过命令行提供的--global 进行更改。

    例如:

    git config --global user.name "First Last"
    git config --global user.email "email@somewhere.com"
    

    更新:

    所有现有的 git 配置都可以通过

    找到
    git config -l
    

    另外,git config -e 会打开一个编辑器进行编辑。

    【讨论】:

    • 问题是关于在每个新创建的存储库中写入 local 配置的默认值。这与全局设置无关,因为本地配置会覆盖全局配置。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-31
    • 2021-01-06
    • 2014-05-16
    • 1970-01-01
    • 2013-11-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多