Bad git config file .git/config

2020-02-23 06: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?

标签: git
23条回答
来,给爷笑一个
2楼-- · 2020-02-23 06:28

I had the same issue for my Android project. So I just did following in Android Studio: File -> Invalidate Cache and Restart. It helped me.

查看更多
趁早两清
3楼-- · 2020-02-23 06:29

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.

查看更多
聊天终结者
4楼-- · 2020-02-23 06:29

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 ( $ nano ~/.gitconfig ), you would put this into your file instead:

[user]
name = WilliamQLiu
email = WilliamQLiu@myemailaddress.com
查看更多
女痞
5楼-- · 2020-02-23 06:29

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.

查看更多
兄弟一词,经得起流年.
6楼-- · 2020-02-23 06:31

This can be happen if you manually edit .gitconfig file . in the C:\Users\.gitconfig (you can edit it using Notepad++ ) open it and check these lines.

 [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)

查看更多
甜甜的少女心
7楼-- · 2020-02-23 06:32

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

查看更多
登录 后发表回答