为什么 `git clone` 在 Windows 上覆盖全局 core.symlinks?

Why does `git clone` override global core.symlinks on Windows?

我发现 git clone 将本地 core.symlinks 值默认设置为 false,即使我已将 core.symlinks 设置为 true

> git config --list --show-origin
file:"C:\ProgramData/Git/config"       core.symlinks=true
file:"C:\ProgramData/Git/config"       core.autocrlf=input
file:"C:\ProgramData/Git/config"       core.fscache=true
file:"C:\ProgramData/Git/config"       color.diff=auto
file:"C:\ProgramData/Git/config"       color.status=auto
file:"C:\ProgramData/Git/config"       color.branch=auto
file:"C:\ProgramData/Git/config"       color.interactive=true
file:"C:\ProgramData/Git/config"       help.format=html
file:"C:\ProgramData/Git/config"       rebase.autosquash=true
-- snip --

> cat .git/config
[core]
    repositoryformatversion = 0
    filemode = false
    bare = false
    logallrefupdates = true
    symlinks = false
    ignorecase = true
[remote "origin"]
    url = https://github.com/saschanaz/eslint-plugin-import
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master

为什么会这样?

这是因为我没有启用 Developer Mode,因此 git 无法在没有管理员权限的情况下创建符号链接。启用它允许未来的克隆获得正确的符号链接。

遗憾的是,

core.symlinks 在 Git 中对于 Windows.

超载了

如果您在创建存储库时将 core.symlinks 设置为 true(无论是 运行 git init 还是 git clone),则 git 实际上会尝试检测您正在创建的工作目录是否支持符号链接,如果支持,它将 然后 将存储库的 core.symlinks 设置为 true。

如果它们不受支持(例如,因为您没有启用开发人员模式),那么存储库的 core.symlinks 配置选项将设置为 false.

因此,第一个选项用作一种机制,您可以在需要符号链接时指定该机制。第二个类似于平台是否支持符号链接的缓存,因此它不需要在每次操作期间都检测到这一点(很像 core.ignorecase)。