【问题标题】:GIT: Can't Push (Strange Config Issue)GIT:无法推送(奇怪的配置问题)
【发布时间】:2014-01-13 04:09:57
【问题描述】:

我正在全新安装 Linux Mint。

尝试从任何存储库推送时出现以下错误:

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/leng/.gitconfig
fatal: Could not read from remote repository.

这很奇怪,因为我肯定有一个支持简单推送行为的版本。

git --version 的输出是git version 1.8.3.2

~/.gitconfig的内容:

[user]
    name = My Name
    email = MyEmail@website.com
[color]
    ui = true
[push]
    default = simple

这就是令人毛骨悚然的地方。

如果我将行为更改为matching(或nothingtrackingcurrent,就此而言),然后尝试推送,我会收到完全相同的错误消息。这怎么可能?它是否以某种方式缓存配置?我什至尝试过重新启动。我什至尝试从系统中完全清除 GIT(并删除 ~/.gitconfig)然后重新安装它。

如果我从 .gitconfig 文件中完全删除 [push] 部分(或者如果我完全删除该文件),然后尝试推送,然后我得到这个:

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)

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/leng/.gitconfig
fatal: Could not read from remote repository.

...所以它似乎是 both 承认我没有选择推动行为,但也说我选择了不受支持的行为。这到底是怎么回事?

如果我完全删除~/.gitconfig,我什至会收到错误消息。

谁能帮我解决这个巫术?

谢谢!

编辑:

这是一个.git/config 请求的文件:

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "origin"]
        url = ssh://{my remote repo}
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master

【问题讨论】:

  • 已经说:(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)
  • @Shivan 我不需要“当前”模式。我不使用旧版本的 Git。但是,即使我将其设置为“当前”,我也会得到同样的错误。
  • 但错误是因为push.default 的值格式错误。 Must be one of nothing, matching, tracking or current.
  • 运行这些命令的计算机上存储库的.git/config 文件中有什么内容?
  • @DavidGrayson 我在我的问题中包含了一个示例配置。不过,我在每个 repo 中都遇到了错误,甚至是我刚刚创建和克隆的全新的 repo(这就是我从中获取配置文件的那个)。感谢您的宝贵时间。

标签: linux git linux-mint


【解决方案1】:

好的,我修好了,但是方法绝对是巫术

我试图通过清除 GIT、删除配置文件、重新安装 GIT、然后创建本地裸存储库、克隆它,然后尝试从那里推送来隔离问题。差不多是这样的:

sudo apt-get purge git-core
rm -f ~/.gitconfig
sudo apt-get install git-core
cd /git
mkdir foo
cd foo
git init --bare
cd /var/www
git clone /git/foo
cd foo
touch blah.txt
git add -A
git config --global user.name "Name"
git config --global user.email "user@email.com"
git commit -m "Blah"
git push

...完全相同的错误消息,没有变化。 (仍然是一些严重的巫术。)

然后,我删除了一个没有本地源的存储库(它通过 SSH 连接到其源),并在删除后重新克隆了存储库(使用新的 git clone ssh://... 命令)。

克隆命令出错:

remote: Malformed value for push.default: simple
remote: Must be one of nothing, matching, tracking or current.

啊哈! 现在它说remote 而不是error。所以遥控器不支持这种行为。 (不过,这并不能解释为什么错误仍然存​​在于具有本地起源的本地存储库中。)

然后我通过 SSH 连接到远程服务器并将那里的 git-core 更新到最新版本,重新尝试从我的本地计算机克隆存储库,并且成功了。

现在,我终于可以git push了。太疯狂了,这也修复了它,所以我可以git push完全本地/var/www/foo也完全本地/git/foo(本地原始裸存储库)。 SSH 连接到这个远程服务器并以某种方式更新它 - WITCHCRAFT - 修复了我本地机器的错误。

为什么完全本地的 repos 关心完全不同的机器的 GIT 版本……超出了我的范围。太疯狂了,太疯狂了。

【讨论】:

  • 很有趣,但是“我的一个存储库通过 SSH 连接到其源并重新克隆它”是什么意思。什么是起源,什么是“它”?
  • @David - 我的一个本地存储库有一个通过 SSH 访问的远程源。源是您从中推送和拉取的裸存储库。我删除了整个本地存储库,然后再次克隆了“它” - 远程裸存储库 - (git clone ssh://...)。
  • +1。恭喜您自行解决问题! :-) 一个可能的解释是您使用了不兼容的不同版本的 Git 客户端和 Git 守护程序。这很奇怪,但在我看来,您的 Git 守护程序根本不支持 push.default (introduced ~5 years ago)。但是正如您所说,这并不能解释本地存储库的不良行为。坦率地说,我现在找不到更好的解释。每当我想到什么或者我对此有新的了解时,我都会再次发表评论。
  • @jweyrich 谢谢!我在想类似的事情 - 但sudo apt-get purge git-core 似乎甚至删除了守护进程和其他相关软件包,所以我不知道在完全清除和重新安装后它会如何持续存在问题!我永远不会忘记这个巫毒。我还是被吓到了。
【解决方案2】:

我在git push 上收到了同样的错误消息。

对我来说,远程用户的 git 是旧版本(1.7.2.5), 我最近更新了远程~/.gitconfig 以包括:

[push]
  default = simple

解决方案是从遥控器的配置中删除此设置。

【讨论】:

  • 感谢您花时间发布对您有用的内容! :)
【解决方案3】:

由于其他人似乎遇到了这个问题,我找到了解决方案 HERE,我想我会发布对我有用的解决方案。

简而言之: 我找到的解决方案是this page。显然,最好的解决方案是升级到较新版本的 Git(如果可能)。然而,这对我来说不是一个选择。在本地机器上,我输入了以下命令:

git config -–global push.default upstream

这消除了我遇到的Malformed value for push.default: simple 错误。但是,我不完全确定 upstream 做了什么。

我的上下文(用于比较):我在远程计算机上有一个空的 (bare) 存储库,我在几个“本地”工作站上有几个存储库。我从远程存储库pull 做一些工作,然后将push 我的工作转移到远程存储库。推/拉是通过 SSH 完成的。大多数时候,在本地机器上工作时,推/拉会导致上述错误。

简而言之,在修复之前,我在远程机器上有以下~/.gitconfig 文件:

[user]
        name = Foo Bar
        email = FooBarPerson@email.com
[diff]
        external = /Users/foobar/bin/git-diff-cmd.sh
[color]
        diff = auto
        status = auto
        branch = auto
[push]
        default = simple

输入上述命令后,我在远程机器上的~/.gitconfig文件变为:

[user]
        name = Foo Bar
        email = FooBarPerson@email.com
[diff]
        external = /Users/foobar/bin/git-diff-cmd.sh
[color]
        diff = auto
        status = auto
        branch = auto
[push]
        default = upstream

版本信息:

  • 远程机器(存储库位置):1.9.4
  • 我的笔记本电脑:1.8.5.2 (Apple Git-48)
  • 我使用的其他计算机:1.7.7.4

这是另一个可能对某些人有用的网站: http://www.lorrin.org/blog/2011/10/03/argumentless-git-pull-and-git-push/comment-page-1/

【讨论】:

  • 感谢您花时间发布您的上下文和解决方案!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多