Git 错误 - 键不包含部分

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45174228/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 05:03:34  来源:igfitidea点击:

Git Error - key does not contain a section

gitgithub

提问by kawnah

I recently transferred a git repository to a new organization. I ran the following:

我最近将一个 git 存储库转移到了一个新组织。我运行了以下内容:

git remote set-url origin https://github.com/organizationname/therepo.git

git remote set-url origin https://github.com/organizationname/therepo.git

I am successfully pulling/pushing from the new location. But now getting the following errors every time I run a git command:

我成功地从新位置拉/推。但是现在每次运行 git 命令时都会收到以下错误:

error: key does not contain a section: repositoryformatversion
error: key does not contain a section: filemode
error: key does not contain a section: bare
error: key does not contain a section: logallrefupdates
error: key does not contain a section: ignorecase
error: key does not contain a section: precomposeunicode

I initially thought it had to do with my config file however those fields are present. The first lines of My /.git/configfile looks like this:

我最初认为它与我的配置文件有关,但是这些字段存在。我的/.git/config文件的第一行如下所示:

repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true

In this answerit suggests to check for --get-regexbut I do not see any reference to that in my config or .gitconfigfiles. It looks like I have 2 git config files:

这个答案中,它建议检查,--get-regex但我在我的配置或.gitconfig文件中没有看到任何对它的引用。看起来我有 2 个 git 配置文件:

/usr/local/git/etc/gitconfig

/usr/local/git/etc/gitconfig

and:

和:

/Users/chmd/.gitconfig

/Users/chmd/.gitconfig

I tried adding those keys to /Users/chmd/.gitconfigfile with no such luck. What step am I missing to clear out these errors? Based on previous answer and research it seems to be my config, but I'm including those fields in my gitconfig?

我尝试将这些密钥添加到/Users/chmd/.gitconfig文件中,但没有这样的运气。我错过了什么步骤来清除这些错误?根据之前的答案和研究,它似乎是我的配置,但我将这些字段包含在我的 gitconfig 中?

回答by axiac

Indeed, the problem is in .git/config. You probably edited it and you removed the name of the section by mistake.

确实,问题出在.git/config. 您可能对其进行了编辑,并且错误地删除了该部分的名称。

The values in Git config file are grouped in sections. The name of each section is placed between square brackets on a separate line.

Git 配置文件中的值按部分分组。每个部分的名称放在单独一行的方括号之间。

The values you posted (from the beginning of your .git/config) should stay in the coresection. Make your .git/configfile look like:

您发布的值(从 的开头.git/config)应保留在该core部分中。让你的.git/config文件看起来像:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ...

回答by zigarn

Git configurationis organized in sections.

Git 配置按部分组织。

It's:

它的:

Your .git/configshould look like this:

.git/config应该是这样的:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    # ...

回答by khem raj regmi

paste the following code to terminal it will open global config file in VI text editor

将以下代码粘贴到终端,它将在 VI 文本编辑器中打开全局配置文件

git config --global --edit

press i to write in VI text editor and remove all the text and paste the following

按 i 在 VI 文本编辑器中写入并删除所有文本并粘贴以下内容

[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true

to save in VI press ESC and :wq and press enter

要保存在 VI 中,请按 ESC 和 :wq 并按 Enter