git - 带 repos 的文件夹的配置

标签 git

我不喜欢 git config --global 因为我使用了更多的帐户。

我也不喜欢每次都设置配置,我想克隆一些 repo。

我正在寻找这样的东西:

folder01/
    ..there is one clonned repo..
folderO2/
    ..there is two clonned repo..

git config <folder> user.email ...

我需要文件夹中的 repos 继承父文件夹的配置。

两个文件夹都不是 repos,只是文件夹。

我将 repos 克隆到某个文件夹中,有时我会删除一些 repo。

非常感谢!

最佳答案

如果你的系统只需要一个配置,你可以用git config --system来配置它。 (作为管理员/root)。

如果您想为多个用户(但不是所有用户)使用相同的配置,您可以在每个用户的主目录中创建此配置和指向该配置的链接。

不可能直接这样做(至少我不知道)。

但是,有一些有趣的事情:

  • 命令 git config有一个 --file option .有了它,您可以配置单独的配置文件。

  • 您可以为您设置配置文件git config --local include.path "<config file>" .

有了它,你可以为你的目录创建一个新的配置文件,当你创建一个目录时,你可以使用 git config --local include.path "<config file>" 设置目录的配置文件。 .

您还可以通过编写脚本来自动执行此操作,该脚本会自动扫描所有目录,例如配置文件并执行 git config --local include.path "<config file>"如果它找到任何文件。

该脚本可能看起来像那样(如果您使用 linux/bash):

#!/bin/bash

git init

initDir="$PWD"

while [ "$PWD" != "/" -a ! -f "./.gitconfig"  ] ; do
        cd ..
done
if [[ -f "./.gitconfig" ]]; then
        configFile="$PWD/.gitconfig"
        cd $initDir
        git config --local include.path "$configFile"
fi

关于git - 带 repos 的文件夹的配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57921814/

相关文章:

git push --all --tags : incompatible

git - 有 .gitnotice 文件吗?

ANDROID STUDIO 3.0升级: GIT AND SUBVERSION

git 和 vimdiff - 一次关闭所有文件

git - 将遗留代码库从 cvs 转移到分布式存储库(例如 git 或 mercurial)。初始存储库设计所需的建议

windows - Android Studio 和 Git - 如何对我的提交进行 GPG 签名?

Git 将 diff 分支到一个新的提交中

git - 更改 Git 远程仓库密码

java - 构建 apache Spark 时出错

Git 如何对我已经推送的(个人)分支进行 rebase ?