Bad git config file .git/config

匿名 (未验证) 提交于 2019-12-03 01:47:02

问题:

In my git repositiory, whenever I do any git commands like git status or 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?

回答1:

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.



回答2:

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

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

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


回答3:

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 config --global -l fatal: bad config file line 1 in C:\Users\/.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.

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.



回答4:

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.



回答5:

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

I managed to solve it by creating a new repo (in a seperate folder) with git init and copying .git/config over from there.

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



回答6:

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].


回答7:

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"

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".

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



回答8:

I had the same problem right after initial installation.

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

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



回答9:

For me it worked when I opened the config folder and deleted all the null characters in it and saved the file again. Then i initiated the build again and git was able to perform the commands after that.



回答10:

Unless you've set the environment variable GIT_CONFIG, your config file is called .gitconfig and is located in your home directory $HOME$ for *nix systems and %HOMEPATH% for Windows (C:\Users\MyName by default).

Source



回答11:

I was getting this error in Windows 8.1 with GitHub for Windows client 2.14.*

None of the git repositories cloned in my local were accessible. 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

So I deleted gitconfig file at this path and closed Git shell and Git client. Starting Git client again and the repository is back to normal.



回答12:

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.

I then re-opened SourceTree (that's what I normally use) and everything except the remotes were there.



回答13:

On Windows I had the same issue, 'fatal: bad config file line 1 in /home/user.name/.gitconfig'. I took a backup and then removed the file. Then navigated into my directory for the repository and was now able to run git commands properly without the error.



回答14:

I had the same problem I open the file and it contains only null characters. Just delete them save and it worked.



回答15:

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.



回答16:

The best they can do is copy all their files in another route except the folder .git then make clone of the last commit that managed to upload and paste the files that moved to the other route so that they are overwrite and allow the new commit.



回答17:

For Cygwin it messed up my username in the .gitconfig file. My username was created as domain\username and apparently that backslash is escaping the 's'.

So, if after you type git status you get this:

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 (i.e. Donald Trump)
  3. Edit the variable email to show a valid email value (i.e. dtrump@whouse.gov)
  4. Edit the variable username to show a simple username with no backslash (i.e. dtrump)

So the suggestion above is useful... Right before you create your git repository (git init), set up these variables right away:

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

Because the default values are most likely not correct.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!