错误的 git 配置文件 .git/config

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9509125/
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-10 13:04:34  来源:igfitidea点击:

Bad git config file .git/config

git

提问by Spencer

In my git repositiory, whenever I do any git commands like git statusor git log, I get the error:
fatal: bad config file line 1 in .git/config
How do I rebuild that file or a new one?

在我的 git 存储库中,每当我执行诸如git status或 之类的任何 git 命令时,都会git log收到错误消息:
fatal: bad config file line 1 in .git/config
如何重建该文件或新文件?

采纳答案by Woody Hayday

For those hitting into this issue (I believe it's due to crashing out git mid init?) in windows, if you have a recent backup of the config file from your git repo's .git/ folder you can fix it by replacing the existing with it (any ref's added since the copy will obviously need re-adding) - not at all ideal but better than loosing all the commits.

对于那些在 Windows 中遇到此问题的人(我认为这是由于 git mid init 崩溃?),如果您最近从 git repo 的 .git/ 文件夹中备份了配置文件,则可以通过用它替换现有文件来修复它(添加任何引用,因为副本显然需要重新添加) - 一点也不理想,但比丢失所有提交要好。

回答by Will

I know on some tutorials they ask you to put the below code, but what they actually mean is that they're the commands you type into the terminal: git config --global user.name "NewUser" git config --global user.email [email protected]

我知道在某些教程中,他们要求您输入以下代码,但实际上它们是您在终端中键入的命令: git config --global user.name "NewUser" git config --global user。电子邮件 [email protected]

If you were modifying the file ( $ nano ~/.gitconfig), you would put this into your file instead:

如果您正在修改文件 ( $ nano ~/.gitconfig),则应将其放入您的文件中:

[user]
name = WilliamQLiu
email = [email protected]

回答by adgoudz

My issue was related to my global config which Git resolved to $HOME/.gitconfig, however the underlying cause happened to be irrespective of the location.

我的问题与我的全局配置有关,Git 解决了这个问题$HOME/.gitconfig,但是根本原因碰巧与位置无关。

> git config --global -l
fatal: bad config file line 1 in C:\Users\<user>/.gitconfig

I have a habit of symlink-ing the config files in my home directory to a nested Git repository for maintaining the files across my multiple development environments. It turns out that Cygwin's implementation of a symbolic link doesn't make much sense to Git running under Windows.

我习惯于将主目录中的配置文件符号链接到嵌套的 Git 存储库,以便在我的多个开发环境中维护这些文件。事实证明,Cygwin 对符号链接的实现对于在 Windows 下运行的 Git 没有多大意义。

I changed the symbolic link to a hard link and somehow this works ok. I was able to verify this by opening the .gitconfig link within Windows; when using a symbolic link the file contained binary data however the hard-linked file contains the content as expected.

我将符号链接更改为硬链接,不知何故这可以正常工作。我可以通过在 Windows 中打开 .gitconfig 链接来验证这一点;使用符号链接时,文件包含二进制数据,但硬链接文件包含预期的内容。

回答by user3216139

Its better to execute the two commands

执行这两个命令比较好

git config --global user.name "NewUser"
git config --global user.email [email protected]

in the terminal. This in turn will update the config file.

在终端。这反过来将更新配置文件。

回答by Nutomic

I had the same problem (Notepad++ showed only NULLcharacters in the file).

我遇到了同样的问题(Notepad++ 只显示NULL文件中的字符)。

I managed to solve it by creating a new repo (in a seperate folder) with git initand copying .git/configover from there.

我设法通过创建一个新的存储库(在单独的文件夹中)git init.git/config从那里复制来解决它。

Remotes were missing after that, but everything worked after readding them manually.

之后遥控器丢失了,但在手动阅读它们后一切正常。

回答by mehul9595

I too had same issue, managed to fix it by below steps.

我也有同样的问题,设法通过以下步骤修复它。

  1. deleted .gitconfig file from, c:\users[username] (created backup incase not worked, but its not needed.)
  2. restarted source tree and File->Open->[your repository].
  1. 从 c:\users[username] 中删除了 .gitconfig 文件(创建的备份柜面不起作用,但不需要。)
  2. 重新启动源树和 File->Open->[your repository]。

回答by Jean-Marie Favre

I get the same symptom. I'm using Cygwin on Windows, and when I launch a process "git clone" for instance the error message is "fatal: bad config line 1 in c:/cygwin/home/myhome/.getconfig"

我得到同样的症状。我在 Windows 上使用 Cygwin,当我启动进程“git clone”时,例如错误消息是“fatal: bad config line 1 in c:/cygwin/home/myhome/.getconfig”

The problem is obviously on the file name which is a mix between windows c: and cygwin/unix path. ;-) What is misleading is the "line 1" message while it should say "config file not found".

问题显然出在文件名上,该文件名是 windows c: 和 cygwin/unix 路径之间的混合。;-) 误导的是“第 1 行”消息,而它应该说“找不到配置文件”。

I don't know how this is produced as I do have neither %HOMEPATH% neither $HOME set

我不知道这是如何产生的,因为我既没有 %HOMEPATH% 也没有设置 $HOME

回答by jordanrh

I had the same problem right after initial installation.

初始安装后我遇到了同样的问题。

"fatal: bad config line 1 in file C:\ProgramData/Git/config"

“致命:文件 C:\ProgramData/Git/config 中的错误配置第 1 行”

I opened notepad as administrator, navigated to the file listed in the error message. The file was also blank but it had spaces/tabs so I deleted them saved the file. And now it works

我以管理员身份打开记事本,导航到错误消息中列出的文件。该文件也是空白的,但它有空格/制表符,所以我删除了它们保存了文件。现在它起作用了

回答by ofri cofri

For me the problem was that I edited the file in Mac TextEdit app, which is set by default to transform "standard" double-quotes into “angled” double-quotes.

对我来说,问题是我在 Mac TextEdit 应用程序中编辑了文件,默认情况下该应用程序设置为将“标准”双引号转换为“有角度的”双引号。

In .git/config, the correctdouble-quotes are: " (UNICODE U+0022 QUOTATION MARK)

在 中.git/config正确的双引号是:" (UNICODE U+0022 QUOTATION MARK)

In my case, I fixed the following line:

就我而言,我修复了以下行:

WRONG: [remote “origin”]

错误的: [remote “origin”]

CORRECT: [remote "origin"]

正确的: [remote "origin"]

PS: If you want that Mac TextEdit doesn't "smartly" change the double-quotes, go to "Preferences" and un-check "smart quotes".

PS:如果您希望 Mac TextEdit 不会“巧妙地”更改双引号,请转到“首选项”并取消选中“智能引号”。

回答by Patricia Heimfarth

Search for the config file and delete all the whitespaces in it worked for me.

搜索配置文件并删除其中的所有空格对我有用。