【问题标题】:Git - fatal: unknown error occured while reading the configuration filesGit - 致命:读取配置文件时发生未知错误
【发布时间】:2016-06-28 08:05:08
【问题描述】:

不确定这是否是发布此问题的正确位置,但是:

当我尝试在我的 Git bash 窗口中执行任何操作时,我收到此错误:

fatal: unknown error occured while reading the configuration files

我在不同的配置下尝试了几次重新安装,并尝试了多次重新启动,但没有任何帮助。我在 Windows 上质疑我的用户名,因为它有一个点 (.)。这会因为某种原因让 Git 感到困惑吗?如果是这样:是否有解决方法?

我似乎也无法找到我的配置文件所在的位置,因为查找它的命令被破坏并显示相同的错误消息。


我在我的电脑上搜索了.gitconfig 文件。我一共找到了4个文件:

  • C:\Program Files\Git\mingw64\etc\.gitconfig
  • C:\Program Files\Git\usr\share\vim\vim74\ftplugin\.gitconfig
  • C:\Program Files\Git\usr\share\vim\vim74\indent\.gitconfig
  • C:\Program Files\Git\usr\share\vim\vim74\syntax\.gitconfig

这是每个文件的内容

...\Git\mingw64\etc.gitconfig

[credential]
helper = manager

...\Git\usr\share\vim\vim74\ftplugin.gitconfig

" Vim filetype plugin
" Language: git config file
" Maintainer:   Tim Pope <vimNOSPAM@tpope.org>
" Last Change:  2009 Dec 24

" Only do this when not done yet for this buffer
if (exists("b:did_ftplugin"))
  finish
endif
let b:did_ftplugin = 1

setlocal formatoptions-=t formatoptions+=croql
setlocal comments=:#,:; commentstring=;\ %s

let b:undo_ftplugin = "setl fo< com< cms<"

...\Git\usr\share\vim\vim74\indent.gitconfig

" Vim indent file
" Language: git config file
" Maintainer:   Tim Pope <vimNOSPAM@tpope.org>
" Last Change:  2013 May 30

if exists("b:did_indent")
  finish
endif
let b:did_indent = 1

setlocal autoindent
setlocal indentexpr=GetGitconfigIndent()
setlocal indentkeys=o,O,*<Return>,0[,],0;,0#,=,!^F

let b:undo_indent = 'setl ai< inde< indk<'

" Only define the function once.
if exists("*GetGitconfigIndent")
  finish
endif

function! GetGitconfigIndent()
  let line  = getline(prevnonblank(v:lnum-1))
  let cline = getline(v:lnum)
  if line =~  '\\\@<!\%(\\\\\)*\\$'
    " odd number of slashes, in a line continuation
    return 2 * &sw
  elseif cline =~ '^\s*\['
    return 0
  elseif cline =~ '^\s*\a'
    return &sw
  elseif cline == ''       && line =~ '^\['
    return &sw
  else
    return -1
  endif
endfunction

Git\usr\share\vim\vim74\syntax.gitconfig

" Vim syntax file
" Language: git config file
" Maintainer:   Tim Pope <vimNOSPAM@tpope.org>
" Filenames:    gitconfig, .gitconfig, *.git/config
" Last Change:  2010 May 21

if exists("b:current_syntax")
  finish
endif

setlocal iskeyword+=-
setlocal iskeyword-=_
syn case ignore
syn sync minlines=10

syn match   gitconfigComment    "[#;].*"
syn match   gitconfigSection    "\%(^\s*\)\@<=\[[a-z0-9.-]\+\]"
syn match   gitconfigSection    '\%(^\s*\)\@<=\[[a-z0-9.-]\+ \+\"\%([^\\"]\|\\.\)*"\]'
syn match   gitconfigVariable    "\%(^\s*\)\@<=\a\k*\%(\s*\%([=#;]\|$\)\)\@=" nextgroup=gitconfigAssignment skipwhite
syn region  gitconfigAssignment  matchgroup=gitconfigNone start=+=\s*+ skip=+\\+ end=+\s*$+ contained contains=gitconfigBoolean,gitconfigNumber,gitConfigString,gitConfigEscape,gitConfigError,gitconfigComment keepend
syn keyword gitconfigBoolean true false yes no contained
syn match   gitconfigNumber  "\d\+" contained
syn region  gitconfigString  matchgroup=gitconfigDelim start=+"+ skip=+\\+ end=+"+ matchgroup=gitconfigError end=+[^\\"]\%#\@!$+ contained contains=gitconfigEscape,gitconfigEscapeError
syn match   gitconfigError  +\\.+    contained
syn match   gitconfigEscape +\\[\\"ntb]+ contained
syn match   gitconfigEscape +\\$+    contained

hi def link gitconfigComment        Comment
hi def link gitconfigSection        Keyword
hi def link gitconfigVariable       Identifier
hi def link gitconfigBoolean        Boolean
hi def link gitconfigNumber     Number
hi def link gitconfigString     String
hi def link gitconfigDelim      Delimiter
hi def link gitconfigEscape     Delimiter
hi def link gitconfigError      Error

let b:current_syntax = "gitconfig"

我运行的是 Windows 7 x64 Professional。该计算机是域网络的一部分。

我在谷歌上搜索了这个问题,当我来到第 11 页却没有任何用处时放弃了。

【问题讨论】:

  • 你有一些已知的好 .gitconfig 文件吗?如果是这样,请尝试在他们之间进行diff 看看是否有不同之处。
  • 所有 vim 配置文件都不感兴趣。至于用于 Winfdows 的 Git,在您的用户配置文件目录中还有“C:\ProgramData\Git\config”和.gitconfig.config\git\config。其中一个文件不可读 - 通常不需要以管理员身份运行 git。
  • 我建议运行 procmon 并注意读取或权限被拒绝错误。

标签: git


【解决方案1】:

对我来说,问题是用户中的 .gitconfig 文件夹/目录// 删除 dir(.gitconfig) 解决了问题,现在可以正常工作了。 click on this link to refer the image for solution

【讨论】:

    【解决方案2】:

    我在作为域网络一部分的机器上安装了 Git 时遇到了同样的问题。我按照this post 第一部分中列出的说明在我的机器上的用户配置文件下创建了$HOME 环境变量,它纠正了问题。

    问题是我们的组策略将主目录设置为网络上的一个位置。 Windows 版 Git 配置为默认使用主目录进行多项设置,并且网络或我的机器(谁知道是什么)上的某些设置更改了对在 Git 需要的此网络位置创建的配置文件的权限,以便函数。

    试试这个:

    1. 以管理员身份运行 Git Bash。
    2. echo $HOME,并记下打印的目录。
    3. 关闭 Git Bash 并以管理员身份运行它
    4. echo $HOME,并将目录与以管理员身份运行时打印的目录进行比较。
    5. 如果步骤 (2) 和 (4) 中打印的目录不同,请按照链接博客文章中的说明将您的 $HOME 环境变量设置为您以管理员身份运行 Git Bash 时打印的目录。

    【讨论】:

      【解决方案3】:

      在“Where does git config --global get written to?”中看到了该错误消息

      问题是此文件夹中的第二个.gitconfig

      C:\Users\myUser.config\git\config
      

      轻微的挑剔,该错误消息将随着 Git 2.9.x/2.10(2016 年第三季度)而改变

      commit 3a39f61commit dc72b50(2016 年 6 月 10 日)Peter Colberg (``)
      (由 Junio C Hamano -- gitster -- 合并于 commit 9d3d0db,2016 年 7 月 6 日)

      config.c:修复错误消息中“发生”的拼写错误

      -       die(_("unknown error occured while reading the configuration files"));
      +       die(_("unknown error occurred while reading the configuration files"));
                                       ^^
      

      【讨论】:

      • 我的系统上不存在这样的文件夹。即使我尝试手动创建该文件,它仍然无法正常工作。
      • @AlexanderJohansen 好的。我只是提到了错误消息中即将发生的变化。
      • @AlexanderJohansen 您可以在使用 C:\git 2.9.0 中解压(未安装)的 git 启动的会话中重试吗?解压github.com/git-for-windows/git/releases/download/…。然后set PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\git 2.9.0;C:\git 2.9.0\bin;C:\git 2.9.0 \cmd;C:\git 2.9.0\usr\bin`。在设置了更简单 PATH 的 CMD 中重试。
      • @AlexanderJohansen 让我们在这里继续。只是为了检查,你能不能创建一个用户 foo,切换到它,看看是否效果更好(排除你的名字和它的点)
      【解决方案4】:

      好的。于是我找到了解决办法,简单到令人唏嘘!

      您所需要做的就是以管理员身份运行git-bash.exe

      我进入C:\Program Files\Git 并将git-bash.exe 设置为始终以管理员身份运行。这样我仍然可以使用我的右键快捷方式并自动以管理员身份运行。

      右键单击git-bash.exe 文件并选择属性。转到兼容性选项卡下,选中底部“以管理员身份运行此程序”的复选框。点击确定,问题就解决了。

      【讨论】:

      • 请解释一下否决票?这可能对可能遇到相同问题的人有用。
      • 一般不需要以管理员身份运行git(除非你想设置系统配置)。这只是表明您的设置有问题。
      • @MrTux 老实说:以管理员身份运行 Git 真的有这么大的问题吗?主要思想是它有效。这就是我所要求的。这样我就可以继续从事我的项目了。
      • 确认:不需要以管理员身份运行。禁用 UAC 会更糟。再次:在以C:\git 2.9.0 中的 git 解压(未安装)开始的会话中重试?解压github.com/git-for-windows/git/releases/download/…。然后set PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\git 2.9.0;C:\git 2.9.0\bin;C:\git 2.9.0\cmd;C:\git 2.9.0\usr\bin。在设置了更简单的PATH 的 CMD 中重试。
      • @VonC 我试过这个:虽然我仍然收到相同的错误消息。
      【解决方案5】:

      检查 C:\users\mylogin.gitconfig 如果你在这里没有找到去 C:\user\myLogin.git.gitconfig 看看它是否对你有读取权限,在安全方面为你提供完全控制。

      【讨论】:

        【解决方案6】:

        遇到了同样的问题。以管理员身份运行有帮助,所以我删除了我能在我的计算机上找到的所有 .gitconfig 文件,它有帮助

        【讨论】:

          【解决方案7】:

          我遇到了同样的错误,我的问题是我的 .config 文件在

          c:\users\myLogin\.gitconfig

          是空的。我添加了以下内容:

          [core]
              repositoryformatversion = 0
              filemode = false
              bare = false
              logallrefupdates = true
              symlinks = false
              ignorecase = true
          [remote "origin"]
              url = <url>
              fetch = +refs/heads/*:refs/remotes/origin/*
          [branch "master"]
              remote = origin
              merge = refs/heads/master
          

          你的 gitconfig 文件是空的吗?

          【讨论】:

            【解决方案8】:

            我在 Windows 上使用 Git 并且遇到了同样的问题,我删除了 .git-credentials 和 .gitconfig 文件并重新启动了 Git,一切正常。

            对我来说,这些文件位于 Windows 的 Documents 文件夹中。

            您可能需要再次添加一些配置,例如 user.name 和 user.email 等。

            【讨论】:

              【解决方案9】:

              上面提供的选项都不适合我。最终修复它的是将 HOME 环境变量设置为指向合理的东西。完成此操作后,git 再次开始正常运行。

              【讨论】:

                【解决方案10】:

                我遇到了完全相同的问题,甚至在完全重新安装 git 后也没有解决。

                要解决这个问题,请在以下位置创建一个空的 .gitconfig 文件:

                C:\Users\<username>\AppData\Local\
                

                希望对你有所帮助。

                【讨论】:

                  猜你喜欢
                  • 1970-01-01
                  • 2018-04-25
                  • 2017-07-02
                  • 2021-03-06
                  • 1970-01-01
                  • 2011-12-01
                  • 2020-12-16
                  • 2015-01-20
                  • 2017-06-29
                  相关资源
                  最近更新 更多