Git 警告:push.default 未设置;它的隐含价值正在改变

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19720711/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 17:14:09  来源:igfitidea点击:

Git warning: push.default is unset; its implicit value is changing

gitpush

提问by HymanSun

When I push to remote in Git, I get this warning:

当我在 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)

To **********************************
   6b9a6d2..3ab1eab  master -> master

What does this warning mean and what should be done about it?

这个警告是什么意思,应该怎么做?

回答by John Szakmeister

This warning was introduced in Git 1.7.11 along with the simplestyle of pushing. The issue is that the current default, matching, can result in inexperienced users force pushing when some branches are behind their remote equivalent because the branches simply aren't up-to-date. The end result is that they end up rewinding the branch and potentially losing their work or someone else's. The simplemode was introduced as a new push.defaultbehavior and will become the default in Git 2.0 (which should hopefully be out sometime early next year).

这个警告是在 Git 1.7.11 中与simple推送风格一起引入的。问题是当前的默认值matching可能会导致没有经验的用户在某些分支落后于远程等效项时强制推送,因为这些分支根本不是最新的。最终的结果是他们最终会倒带分支并可能丢失他们的工作或其他人的工作。该simple模式是作为一种新push.default行为引入的,并将成为 Git 2.0 中的默认设置(有望在明年初推出)。

The new simplebehavior is a lot like the upstreamsetting: it only pushes the current branch that you're currently on, if it has a remote branch that it's tracking. It adds one extra criteria: the remote branch must have the same name as the local one.

simple行为很像upstream设置:它只推送您当前所在的当前分支,如果它有一个正在跟踪的远程分支。它增加了一个额外的条件:远程分支必须与本地分支同名。

As you discovered, the way to get rid of the message is to set push.default. To get the new behavior, use:

正如您所发现的,摆脱消息的方法是设置push.default. 要获得新行为,请使用:

git config --global push.default simple

To get Git's default behavior but without the warning message, use:

要获得 Git 的默认行为但没有警告消息,请使用:

git config --global push.default matching

I'd really advise againstusing matching though. In general, most people really want the new simplebehavior, or upstream.

不过,我真的建议不要使用匹配。一般来说,大多数人真的想要新的simple行为,或者upstream.

回答by VonC

Update February 2016:

2016 年 2 月更新

git 2.8(March 2016) removed that big warning message.

git 2.8(2016 年 3 月)删除了那个大警告消息

See commit 2f27520(25 Feb 2016) by Matthieu Moy (moy).
(Merged by Junio C Hamano -- gitster--in commit 15be621, 26 Feb 2016)

请参阅Matthieu Moy ( ) 的commit 2f27520(2016 年 2 月 25 日(由Junio C Hamano合并-- --commit 15be621,2016 年 2 月 26 日)moy
gitster

push: remove "push.default is unset" warning message

The warning was important before the 2.0 transition, and remained important for a while after, so that new users get push.defaultexplicitly in their configuration and do not experience inconsistent behavior if they ever used an older version of Git.

The warning has been there since version 1.8.0 (Oct 2012), hence we can expect the vast majority of current Git users to have been exposed to it, and most of them have already set push.defaultexplicitly. The switch from 'matching' to 'simple' was planned for 2.0 (May 2014), but actually happened only for 2.3 (Feb 2015).

Today, the warning is mostly seen by beginners, who have not set their push.defaultconfiguration (yet). For many of them, the warning is confusing because it talks about concepts that they have not learned and asks them a choice that they are not able to make yet. See for example "Warning: push.default is unset; its implicit value is changing in Git 2.0" (1260 votes for the question, 1824 for the answer as of writing)

Remove the warning completely to avoid disturbing beginners. People who still occasionally use an older version of Git will be exposed to the warning through this old version.

Eventually, versions of Git without the warning will be deployed enough and tutorials will not need to advise setting push.defaultanymore.

push: 删除 " push.default is unset" 警告信息

该警告在 2.0 过渡之前很重要,并且在一段时间之后仍然很重要,因此新用户可以push.default明确地了解他们的配置,并且如果他们曾经使用过旧版本的 Git,则不会遇到不一致的行为。

该警告自 1.8.0 版(2012 年 10 月)以来一直存在,因此我们可以预期绝大多数当前的 Git 用户都已经接触过它,并且其中大多数已经push.default明确设置。从“匹配”到“简单”的转换计划在 2.0(2014 年 5 月)中进行,但实际上仅在 2.3(2015 年 2 月)中发生。

今天,警告主要被初学者看到,他们还没有设置他们的 push.default配置。对于他们中的许多人来说,警告是令人困惑的,因为它谈论的是他们还没有学到的概念,并要求他们做出一个他们还无法做出的选择。例如,参见“警告:push.default 未设置;它的隐含值在 Git 2.0 中正在改变”(1260 票支持该问题,1824 票支持答案截至撰写本文)

完全删除警告以避免打扰初学者。仍然偶尔使用旧版本 Git 的人将通过这个旧版本暴露于警告。

最终,没有警告的 Git 版本将被部署足够多,教程将不再需要建议设置push.default



Original answer (March 2014)

原始答案(2014 年 3 月)

That warning will soon change in git 2.0 (Q2 2014), with commit 289ca27and commit 11037ee:

该警告将很快在 git 2.0(2014 年第二季度)中更改,提交 289ca27提交 11037ee

push.default is unset; its implicit value has changedin Git 2.0 from 'matching' to 'simple'.
To squelch this message and maintain the traditionalbehavior, use:

push.default 未设置;其隐含的值已经改变在GIT中2.0从“匹配的”,以“简单”。
要压制此消息并保持传统行为,请使用:

git config --global push.default matching

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

要立即取消此消息并采用新行为,请使用:

git config --global push.default simple

When push.defaultis set to 'matching', git will push local branches to the remote branches that already exist with the same name.

Since Git 2.0, Git defaults to the more conservative 'simple' "behavior, which only pushes the current branch to the corresponding remote branch that 'git pull' uses to update the current branch.

push.default设置为 ' matching' 时,git 会将本地分支推送到已经存在的同名远程分支。

从 Git 2.0 开始,Git 默认采用更保守的 ' simple' 行为,它只会将当前分支推送到 ' git pull' 用于更新当前分支的相应远程分支。

See more at "Why is pushing to matching the default in Git?".

请参阅“为什么要推送到 Git 中的默认值?”。

回答by bazi.the.developer

I encountered the same issue not to a while ago. I solved this by,

不久前我遇到了同样的问题。我解决了这个问题,

  • first cloning my new branch (UAT)
  • then pushing to that branch (UAT)
  • 首先克隆我的新分支(UAT)
  • 然后推到那个分支(UAT)