"git init" 失败了,怎么办?

15

这个问题不同于"Bad git config file .git/config",因为它在使用 git init 时失败。

看起来 /home/mirror/.gitconfig 没有问题:

[mirror@home php]$ git init
error: Malformed value for push.default: simple
error: Must be one of nothing, matching, tracking or current.
fatal: bad config file line 8 in /home/mirror/.gitconfig

这是 ~/.gitignore 文件的内容:

cat ~/.gitconfig
[alias]
        lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
[user]
        email = xxxxxx@gmail.com
        name = xxxxx
[push]
        default = simple

4
这个错误信息似乎非常明确,不是 default 的有效值之一,而且必须是建议中的其中一个。简单(simple)不是有效值。 - Yno
1
实际上,我正在使用git 1.8.0版本。当我第一次尝试使用git push命令时,我收到了警告说明push.default未设置。因此,我"采用了新的行为"并执行了git config --global push.default simple命令。现在,在尝试执行pod install命令时,我遇到了这个错误。 - Brett Ryan
2
抱歉,我已经找到了问题所在。我刚刚安装了Xcode命令行工具,这覆盖了我的Git版本并将其恢复为1.7.10.2 - Brett Ryan
注意:从Git 2.2(2014年第四季度)开始,错误消息将显示“bad config file line 7”(而不是第8行)。请参见下面的我的答案 - VonC
6个回答

22

Simple选项是在git v1.7.11中添加的。如果您的git版本较旧,此选项不存在。只需从您的conf中删除它,就可以使用init初始化存储库。

请参见文档


我遇到了这个问题,因为我在我的台式机上使用Ubuntu 13.10,但是运行一个使用默认precise64.box(12.04)的Vagrant虚拟机,显然12.04的最新git软件包是1.7.9.5。 - odigity

6

现在git 1.8版本已经发布,这个问题一直出现。幸运的是,git现在的提示信息非常有帮助:

warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:

   git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

   git config --global push.default simple

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

例如,Emacs 对 Git 的接口(vc)不理解参数“simple”,所以目前最好使用参数“matching”。

遇到了这个问题,它告诉我可以选择哪些选项(无、匹配、跟踪或当前),但没有建议使用哪一个。我选择了当前,一切似乎都很好。 - Nubtacular
这真是救命稻草。 - Kumar Saurabh

5
尝试更新配置,使用matching替代simple,用于push.default
git config --global push.default matching

或者

git config push.default matching

1
请注意,鉴于问题出现在以下位置,因此确定问题可能会有问题:
  • 第7行(default = simple),
  • 不是第8行(此处不存在)
解决方案:
  • 更改第7行的值可以解决问题(git config --global push.default matching
  • 删除配置也有帮助作用(git config --global --unset-all push.default

但更重要的是,从git 2.2(2014年第四季度)开始,git config错误行号将准确无误
请参阅提交b3b3f60,由Matthieu Moy (moy)提供:

config.c:修复错误中行号的准确性

如果回调函数向git_config*()系列返回负值,则在打印行号和文件名时调用die()
目前打印的行号偏移一个,因此打印了错误的行号。

在调用回调函数期间使linenr指向我们刚刚解析的行,以便在错误消息中获得准确的行号。


1

如果您使用的是早于1.7.11版本的Git,则请使用类似模式current而不是simple

git config --global push.default current

0

我在搜索推送/拉取时遇到了Malformed value for push.default: simple错误,因此我想其他人也可能会遇到同样的问题。

这里有一个相关的问题,为路人提供更多信息(请看我的答案末尾还有更多链接): GIT: Can't Push (Strange Config Issue)

特别注意,这个错误似乎是由于某个地方使用了旧版本的Git引起的。最好的解决方法是在所有机器上更新到最新版本的Git。

如果您无法这样做,只需运行以下命令(正如@morefromalan所提到的):

git config --global push.default matching

或者

git config --global push.default upstream

为了摆脱错误,需要更改push操作的默认行为,如此处所述。你可能也需要对pullpush进行这样的更改,但我只更改了默认的push行为为upstream,似乎可以正常工作。

祝好运!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接