简体   繁体   English

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

[英]Bad git config file .git/config

In my git repositiory, whenever I do any git commands like git status or git log , I get the error:在我的 git 存储库中,每当我执行任何 git 命令(如git statusgit log )时,都会收到错误消息:
fatal: bad config file line 1 in .git/config
How do I rebuild that file or a new one?如何重建该文件或新文件?

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

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 newuser@example.com我知道在某些教程中,他们要求您输入以下代码,但实际上它们是您在终端中键入的命令: git config --global user.name "NewUser" git config --global user。电子邮件 newuser@example.com

If you were modifying the file ( $ nano ~/.gitconfig ), you would put this into your file instead:如果您正在修改文件( $ nano ~/.gitconfig ),您可以将其放入您的文件中:

[user]
name = WilliamQLiu
email = WilliamQLiu@myemailaddress.com

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 ,但是根本原因恰好与位置$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.我习惯于将主目录中的配置文件符号链接到嵌套的 Git 存储库,以便在我的多个开发环境中维护这些文件。 It turns out that Cygwin's implementation of a symbolic link doesn't make much sense to Git running under Windows.事实证明,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;我可以通过在 Windows 中打开 .gitconfig 链接来验证这一点; when using a symbolic link the file contained binary data however the hard-linked file contains the content as expected.使用符号链接时,文件包含二进制数据,但硬链接文件包含预期的内容。

Its better to execute the two commands执行这两个命令比较好

git config --global user.name "NewUser"
git config --global user.email newuser@example.com

in the terminal.在终端。 This in turn will update the config file.这反过来将更新配置文件。

I had the same problem (Notepad++ showed only NULL characters in the file).我遇到了同样的问题(Notepad++ 只显示文件中的NULL字符)。

I managed to solve it by creating a new repo (in a seperate folder) with git init and copying .git/config over from there.我设法通过使用git init创建一个新的 repo(在一个单独的文件夹中)并从那里复制.git/config来解决它。

Remotes were missing after that, but everything worked after readding them manually.之后遥控器丢失了,但在手动阅读它们后一切正常。

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.)从 c:\\users[username] 中删除 .gitconfig 文件(创建的备份柜面不起作用,但不需要。)
  2. restarted source tree and File->Open->[your repository].重新启动源树和 File->Open->[your repository]。

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.问题显然出在文件名上,该文件名是 windows c: 和 cygwin/unix 路径之间的混合。 ;-) What is misleading is the "line 1" message while it should say "config file not found". ;-) 误导的是“第 1 行”消息,而它应该说“找不到配置文件”。

I don't know how this is produced as I do have neither %HOMEPATH% neither $HOME set我不知道这是如何产生的,因为我既没有 %HOMEPATH% 也没有设置 $HOME

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现在它起作用了

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 correct double-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 不会“巧妙地”更改双引号,请转到“首选项”并取消选中“智能引号”。

I was getting this error in Windows 8.1 with GitHub for Windows client 2.14.*我在 Windows 8.1 中使用 GitHub for Windows 客户端 2.14 收到此错误。*

None of the git repositories cloned in my local were accessible.在我本地克隆的 git 存储库均不可访问。 Branches names, changed files, history, etc. were not visible.分支名称、更改的文件、历史记录等不可见。

Opening the Git Shell and trying to check repository status using git status was giving a error message fatal: bad config file ... at C:\\Users\\MyUser\\AppData\\Local\\GitHub\\PortableGit_xxxxx06exx6fdf878271f7fe636a147ff37326ad\\etc\\gitconfig打开 Git Shell 并尝试使用git status检查存储库状态会给出错误消息fatal: bad config file ... at C:\\Users\\MyUser\\AppData\\Local\\GitHub\\PortableGit_xxxxx06exx6fdf878271f7fe636a147ff37326ad\\etc\\gitconfig

So I deleted gitconfig file at this path and closed Git shell and Git client.所以我删除了这个路径下的 gitconfig 文件并关闭了 Git shell 和 Git 客户端。 Starting Git client again and the repository is back to normal.再次启动 Git 客户端,仓库恢复正常。

I deleted .git/config at the root of my repository folder because that's the bad config file name that was given in the error message.我删除了存储库文件夹根.git/config ,因为这是错误消息中给出的错误配置文件名。

I then re-opened SourceTree (that's what I normally use) and everything except the remotes were there.然后我重新打开了 SourceTree(这是我通常使用的),除了遥控器之外的所有东西都在那里。

For me, i opened the config file and deleted everything in it.对我来说,我打开了配置文件并删除了其中的所有内容。 I backed up the repository and re-cloned the repository.我备份了存储库并重新克隆了存储库。 I then manually applied my changes from the backed-up repository.然后我从备份的存储库中手动应用了我的更改。

I should be noted that remote tracking information will be lost when the config is cleared.需要注意的是,清除配置后,远程跟踪信息将丢失。 You can re-add the remote host but proved tedious for me.您可以重新添加远程主机,但事实证明对我来说很乏味。

他们能做的最好的事情是将所有文件复制到另一个路径中,除了文件夹 .git 然后克隆上次提交,该提交设法上传并粘贴移动到另一个路径的文件,以便它们被覆盖并允许新提交。

For Cygwin it messed up my username in the .gitconfig file.对于 Cygwin,它在.gitconfig文件中弄乱了我的用户名。 My username was created as domain\\username and apparently that backslash is escaping the 's'.我的用户名被创建为域\\用户名,显然反斜杠正在转义“s”。

So, if after you type git status you get this:所以,如果在你输入git status你得到这个:

fatal: bad config line 2 in file /cygdrive/c/Users/yourname/.gitconfig

Then do this:然后这样做:

  1. vi /cygdrive/c/Users/yourname/.gitconfig
  2. Edit the variable name to show a normal name (ie Donald Trump)编辑变量名称以显示正常名称(即唐纳德特朗普)
  3. Edit the variable email to show a valid email value (ie dtrump@whouse.gov)编辑变量email以显示有效的电子邮件值(即 dtrump@whouse.gov)
  4. Edit the variable username to show a simple username with no backslash (ie dtrump)编辑变量username以显示没有反斜杠的简单用户名(即 dtrump)

So the suggestion above is useful... Right before you create your git repository ( git init ), set up these variables right away:所以上面的建议很有用......在你创建你的 git 存储库( git init )之前,立即设置这些变量:

git config --global user.name "NewUser"
git config --global user.email newuser@example.com

Because the default values are most likely not correct.因为默认值很可能不正确。

What worked for me on Windows was just to copy the config files present in C:\\ProgramData\\Git\\config from another machine.Windows上对我C:\\ProgramData\\Git\\config只是从另一台机器复制C:\\ProgramData\\Git\\config存在的配置文件。 It's new content became what's shown below, which replaced the gibberish that was there before:它的新内容变成了下图,取代了之前的胡言乱语:

[core]
    symlinks = false
    autocrlf = true
    fscache = true
[color]
    diff = auto
    status = auto
    branch = auto
    interactive = true
[help]
    format = html
[rebase]
    autosquash = true

If your .gitconfig file seems to be fine (having correct data) you can copy and paste the same data again into it so that the file edit date is modified.如果您的 .gitconfig 文件似乎没问题(具有正确的数据),您可以将相同的数据再次复制并粘贴到其中,以便修改文件编辑日期。 This seemed to work fine for me.这对我来说似乎很好。 And just to avoid the issue in future take a backup of the same file and save as "backup.gitconfig_bak" or any name you like.为了避免将来出现问题,请备份同一文件并另存为“backup.gitconfig_bak”或您喜欢的任何名称。

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

On Jenkins, check the error message for the git-hash-string.在 Jenkins 上,检查 git-hash-string 的错误消息。 Just delete the /var/jenkins/home/caches/git-hash-string git-hash-string@tmp.只需删除 /var/jenkins/home/caches/git-hash-string git-hash-string@tmp。 You may need root permissions to delete all files from the git-hash-string/.git folder.您可能需要 root 权限才能从 git-hash-string/.git 文件夹中删除所有文件。

When you restart the build, everything works fine again.当您重新启动构建时,一切正常。

I just had the same problem after I changed the email which was on the config file.在更改配置文件中的电子邮件后,我遇到了同样的问题。 I signed up for git using xxxx@gmail.com , then git generated an email for me like xxxxxx@users.noreply.github.com .我使用xxxx@gmail.com注册了 git,然后 git 为我生成了一封电子邮件,如xxxxxx@users.noreply.github.com The original email on the config file was xxxxxx@users.noreply.github.com .配置文件上的原始电子邮件是xxxxxx@users.noreply.github.com Changing it to the email I signed up with xxxx@gmail.com caused the problem.将其更改为我使用xxxx@gmail.com注册的电子邮件导致了问题。 To solve it, I logged into my git account online, visited Settings and navigated to the Email section and located the GitHub generated email from this section that reads like:为了解决这个问题,我在线登录了我的 git 帐户,访问了设置并导航到了电子邮件部分,并找到了来自该部分的 GitHub 生成的电子邮件,内容如下:

Primary email address Because you have email privacy enabled, xxxxx@gmail.com will be used for account-related notifications as well as password resets. xxxx@users.noreply.github.com will be used for web-based Git operations (eg edits and merges).

From the console, I run sudo nano ~/.gitconfig Entered my computer password, then changed the email from xxxx@gmail.com back to the Github email xxxx@users.noreply.github.com .从控制台,我运行sudo nano ~/.gitconfig输入我的计算机密码,然后将电子邮件从xxxx@gmail.com更改回 Github 电子邮件xxxx@users.noreply.github.com Then hit (ctr + O) to save, then hit enter, then hit (ctr + x) to close the terminal.然后按 (ctr + O) 保存,然后按 Enter,然后按 (ctr + x) 关闭终端。 To be sure it worked, I cloned the repo again using git clone https://github.com/xxxxx where xxxx is the repo and it worked.为了确保它有效,我再次使用git clone https://github.com/xxxxx克隆了 repo,其中 xxxx 是 repo 并且它有效。 :) :)

This can be happen if you manually edit .gitconfig file .如果您手动编辑.gitconfig文件,就会发生这种情况。 in the C:\\Users\\.gitconfig (you can edit it using Notepad++ ) open it and check these lines.在 C:\\Users\\.gitconfig (您可以使用 Notepad++ 编辑它)中打开它并检查这些行。

 [user]
        name = <your username>
        email = <your email>
    [core] 
        editor = <editor location>

you can change those line.你可以改变那些行。 if you add wrong line to editor variable it can lead to an error.如果向编辑器变量添加错误的行,则可能会导致错误。 simply you can delete this line.只需删除此行即可。 but make sure to get back up of it.但一定要恢复它。 Or you can check right code/path to connect with your text editor and replace it with new working code/path.或者您可以检查正确的代码/路径以连接到您的文本编辑器并将其替换为新的工作代码/路径。

Then save it.然后保存。 (this can be more helpful to android studio users) (这对android studio用户更有帮助)

I don't see a way to find the exact error, git only shows a line number, so I'm posting my troubleshooting steps in case it helps anyone.我没有找到找到确切错误的方法, git只显示一个行号,所以我发布了我的故障排除步骤,以防它对任何人有帮助。

I had this problem trying to add an alias to my ~/.gitconfig global file via a text editor (emacs).我在尝试通过文本编辑器 (emacs) 向~/.gitconfig全局文件添加别名时遇到了这个问题。 I discovered my problem by instead using this command to edit the config:我通过使用此命令来编辑配置发现了我的问题:

git config --global alias.<my_alias> 'my new command'

I was creating an alias to show just the branch that I am on:我正在创建一个别名来仅显示我所在的分支:

$ git config --global alias.thisbranch '!thisbranch() { git branch | grep \* | cut -d " " -f2; }; thisbranch'

The problem was that the * character needed to have a \\\\ double escape in the ~/.gitconfig file since the \\ escape character needed to be escaped (the command was now nested in a string), but I was using only the single escape character \\ .问题是*字符需要在~/.gitconfig文件中有一个\\\\双转义,因为需要转义\\转义字符(命令现在嵌套在一个字符串中),但我只使用了单个转义字符\\

So my git config looks like this now:所以我的 git 配置现在看起来像这样:

[alias]
        ...
        ...
        thisbranch = "!thisbranch() { git branch | grep \\* | cut -d \" \" -f2; }; thisbranch"

I had the same issue for my Android project.我的 Android 项目也遇到了同样的问题。 So I just did following in Android Studio: File -> Invalidate Cache and Restart.所以我只是在 Android Studio 中执行了以下操作:文件 -> 使缓存无效并重新启动。 It helped me.它帮助了我。

我有类似的推送问题,我可以使用以下方法修复它:

git config --global push.default matching

First of all, a file corruption may be a symptom of file system problems (it was in my case), so to prevent further data loss, boot into the rescue mode, and before mounting the partition run disk check utility on it (eg fsck -n or xfs_repair -n ).首先,文件损坏可能是文件系统问题的症状(在我的情况下),因此为了防止进一步的数据丢失,启动进入救援模式,并在安装分区之前运行磁盘检查实用程序(例如fsck -nxfs_repair -n )。

But if you are using Jenkins , then finding the corrupted .git/config file may not be easy.但是如果您使用的是 Jenkins ,那么找到损坏的.git/config文件可能并不容易。 It is stored locally in at least two copies:它在本地存储至少两个副本:

  • in the local copy of the remote repo cloned by Jenkins into <JENKINS_HOME>/<remote_repo_name> AND在 Jenkins 克隆到<JENKINS_HOME>/<remote_repo_name>的远程<JENKINS_HOME>/<remote_repo_name>的本地副本中,并且
  • cached in one of the many git-* folders in <JENKINS_HOME>/caches .缓存在<JENKINS_HOME>/caches的许多git-*文件夹之一中。

对于我来说是删除文件 .gitconfig 并且它解决了

我从我的目录中删除 [.git] 并使用 [git init] 再次重新初始化,一切都对我有用

I was facing the same issue!我面临同样的问题!

The simple solution is that: Delete your flutter SDK and download the latest version of flutter SDK.简单的解决方案是:删除你的flutter SDK并下载最新版本的flutter SDK。

You can download it by the following link: https://docs.flutter.dev/get-started/install您可以通过以下链接下载它: https ://docs.flutter.dev/get-started/install

It happens when Flutter releases the new version of flutter SDK but you are running a lower version, so some libraries show you an error.当 Flutter 发布新版本的 Flutter SDK 但您运行的是较低版本时,会发生这种情况,因此某些库会显示错误。

I was also facing the same issue,so i went to the file path and c:\\User\\.gitconfig and deleted all contents inside it and saved it.我也面临同样的问题,所以我转到文件路径和 c:\\User\\.gitconfig 并删除其中的所有内容并保存。 Now it is working $ git --version git version 2.22.0.windows.1现在它正在工作 $ git --version git version 2.22.0.windows.1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM