mac中的系统级git配置

时间:2015-03-06 14:55:18

标签: macos git

我能够在常规位置查看全局和本地配置文件。

但如果我输入

git config --system --list

它给了我

fatal: unable to read config file '/Library/Developer/CommandLineTools/usr/etc/gitconfig': No such file or directory
  • 知道它为什么看那里?
  • 为什么没有设定?
  • 在哪里
  • Mac的系统git配置位置?

/etc/gitconfig$HOME/.config/git没有文件(规定的位置分别得到* nix和osx)

  

修改

sudo git config --system --list

无效

2 个答案:

答案 0 :(得分:3)

@Abhijit Mazumder:

我知道这是一个老问题,但在尝试在我的mac上设置系统级git配置值时我遇到了类似的问题,我想我会在这里发布我的解决方案,以防它可以帮到你。

  

注意:我强烈怀疑,如果你只是创建   '/ Library / Developer / CommandLineTools / usr / etc /'目录并创建一个   在该目录中名为gitconfig的文件,然后您尝试   查看或设置系统级git配置值将成功。

我在mac上设置系统级git配置值的第一次尝试是:

git config --system alias.cl clone

这导致错误:

error: could not lock config file /Applications/Xcode.app/Contents/Developer/usr/etc/gitconfig: No such file or directory

我想也许我需要在命令中添加'sudo':

sudo git config --system alias.cl clone

但是用'sudo'运行命令给了我同样的错误:

error: could not lock config file /Applications/Xcode.app/Contents/Developer/usr/etc/gitconfig: No such file or directory

所以,从我mac上的根目录开始,我切换到错误中提到的'usr'目录,只是为了看看那里有什么:

cd Applications/Xcode.app/Contents/Developer/usr/

我很惊讶地发现没有'etc'目录。我看到的唯一目录是'bin','lib','libexec'和'share'。

所以我决定创造缺失的东西。我首先创建了一个'etc'目录:

sudo mkdir etc

然后在'etc'目录中创建了一个gitconfig文件:

sudo touch etc/gitconfig

然后我可以使用以下命令设置系统级git配置值:

sudo git config --system alias.cl clone

为了确认实际设置了系统级别的git配置值,我查看了gitconfig文件的内容。

我在'usr'目录中首次使用了unix'cat'命令:

cat etc/gitconfig

'cat'命令的输出是:

[alias]
    cl = clone

然后我使用git命令(你试图在你的问题中使用的那个)检查我的系统级别git配置值是否已设置:

git config --system --list

此命令的输出为:

alias.cl=clone

为确保我将文件放在正确的位置,我需要做的最后一件事是尝试我创建的别名,所以我尝试了运行:

git cl

使用我创建的别名运行此命令会产生以下输出,这确认了一切正常:

You must specify a repository to clone.

usage: git clone [<options>] [--] <repo> [<dir>]

    -v, --verbose         be more verbose
    -q, --quiet           be more quiet
    --progress            force progress reporting
    -n, --no-checkout     don't create a checkout
    --bare                create a bare repository
    --mirror              create a mirror repository (implies bare)
    -l, --local           to clone from a local repository
    --no-hardlinks        don't use local hardlinks, always copy
    -s, --shared          setup as shared repository
    --recursive           initialize submodules in the clone
    --recurse-submodules  initialize submodules in the clone
    --template <template-directory>
                          directory from which templates will be used
    --reference <repo>    reference repository
    --dissociate          use --reference only while cloning
    -o, --origin <name>   use <name> instead of 'origin' to track upstream
    -b, --branch <branch>
                          checkout <branch> instead of the remote's HEAD
    -u, --upload-pack <path>
                          path to git-upload-pack on the remote
    --depth <depth>       create a shallow clone of that depth
    --single-branch       clone only one branch, HEAD or --branch
    --separate-git-dir <gitdir>
                          separate git dir from working tree
    -c, --config <key=value>
                          set config inside the new repository

答案 1 :(得分:1)

我没有遇到此错误,因为我的机器仅供我使用,因此设置--global级别就足够了,但该位置看起来合理(我假设您正在使用Xcode提供的git命令行工具)。

使用sudo配置您想要的功能:

$ sudo git config --system <name> <value>
相关问题