“git init”失败,怎么了?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12294787/
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
"git init" failed, what's wrong?
提问by hugemeow
This issue is not same as "Bad git config file .git/config", since it failed when using git init
.
这个问题与“ Bad git config file .git/config”不同,因为它在使用.git时失败了git init
。
It seems there is nothing wrong with /home/mirror/.gitconfig:
/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
This is the content of ~/.gitignore:
这是 ~/.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 = [email protected]
name = xxxxx
[push]
default = simple
回答by Kim E
Simple was added in git v1.7.11. If your git version is older, this option doesn't exist. Simply remove it from your conf and you'll be able to init repos.
Simple 是在 git v1.7.11 中添加的。如果您的 git 版本较旧,则此选项不存在。只需从您的 conf 中删除它,您就可以初始化 repos。
See https://raw.github.com/git/git/master/Documentation/RelNotes/1.7.11.txt
见https://raw.github.com/git/git/master/Documentation/RelNotes/1.7.11.txt
回答by Heikki
This problem keeps coming up now that git 1.8 is out. Luckily the message from git is now very helpful:
现在 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)
For example, emacs interface to git (vc) does not understand the argument 'simple', so you are better off using the argument 'matching' for the time being.
例如,git (vc) 的 emacs 接口不理解参数“简单”,因此您最好暂时使用参数“匹配”。
回答by morefromalan
Try updating config to use matching
instead of simple
for push.default
.
尝试更新配置以使用matching
而不是simple
for push.default
。
git config --global push.default matching
or
或者
git config push.default matching
回答by VonC
Note that it can be problematic identifying the issue, considering the problem is at:
请注意,确定问题可能会出现问题,考虑到问题位于:
- line 7 (
default = simple
), - notline 8 (which here doesn't exist)
- 第 7 行 (
default = simple
), - 不是第 8 行(此处不存在)
Solutions:
解决方案:
- Changing the value at line 7 solves the issue (
git config --global push.default matching
) - removing the configcan help too (
git config --global --unset-all push.default
)
- 更改第 7 行的值可以解决问题 (
git config --global push.default matching
) - 删除配置也有帮助 (
git config --global --unset-all push.default
)
But most importantly, starting git 2.2 (Q4 2014), the git config error line number will be accurate.
See commit b3b3f60, by Matthieu Moy (moy
):
但最重要的是,从 git 2.2(2014 年第四季度)开始,git config 错误行号将是准确的。
见提交b3b3f60,由马修·莫伊(moy
):
config.c
: fix accuracy of line number in errors
config.c
: 修复错误中行号的准确性
If a callback returns a negative value to
git_config*()
family, they calldie()
while printing the line number and the file name.
Currently the printed line number is off by one, thus printing the wrong line number.Make
linenr
point to the line we just parsed during the call to callback to get accurate line number in error messages.
如果回调向
git_config*()
family返回负值,则它们die()
在打印行号和文件名时调用。
当前打印的行号偏移一,因此打印错误的行号。做
linenr
点我们在通话过程中只是解析回调得到错误信息准确的行号的行。
回答by Pleymor
Use the similar mode current
instead of simple
if you use a version of Git older than 1.7.11.
使用类似的模式current
,而不是simple
如果你使用一个版本的Git比1.7.11老。
git config --global push.default current
回答by jvriesem
Since I came across this when searching for the Malformed value for push.default: simple
error I got when pushing/pulling, I figured other people may as well.
由于我在搜索Malformed value for push.default: simple
推/拉时遇到的错误时遇到了这个问题,我想其他人也可以。
Here's a related question that provides more information for the passer-by (see my answer at the end for more links, too): GIT: Can't Push (Strange Config Issue)
这是一个相关问题,它为路人提供了更多信息(有关更多链接,请参阅我最后的回答): GIT:无法推送(奇怪的配置问题)
Note in particular that this error seems to be caused by having an older version of Git somewhere. The best solution is to update to the latest version of Git on all machines.
请特别注意,此错误似乎是由于某处使用旧版本的 Git 引起的。最好的解决方案是在所有机器上更新到最新版本的 Git。
If this is not possible for you, simply run the following commands (as mentioned by @morefromalan):
如果这对您来说是不可能的,只需运行以下命令(如@morefromalan 所述):
git config --global push.default matching
or
或者
git config --global push.default upstream
to get rid of the error. This changes the default behavior of push
operations as described HERE. You mayhave to to this for pull
as well as push
, but it seems to be working for me just having changed the default push
behavior to upstream
.
摆脱错误。这改变的默认行为push
所描述的操作这里。您可能不得不这样pull
做push
,但它似乎对我有用,只是将默认push
行为更改为upstream
.
Good luck!
祝你好运!