`git push origin` 的结果是什么?

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

What is the result of `git push origin`?

git

提问by John Bachir

I worked on my local feature branch, foo. Then I wanted to push that new branch to origin so others could work on it. The normal way to do this is:

我在我的本地功能分支 foo 上工作。然后我想把这个新分支推到原点,这样其他人就可以处理它了。执行此操作的正常方法是:

git push origin foo:foo

Which I eventually did, and it worked completely as expected, pushing up 61 objects. Before doing that, on a whim, I tried:

我最终做到了,它完全按预期工作,推了 61 个对象。在这样做之前,一时兴起,我尝试过:

git push origin

Thinking maybe it would default to making a new remote branch based on the name of my local branch. The output was normal push output, with only 13 objects pushed up. The results were imperceivable. Nothing new showed up for the other devs or in my local repo after a fetch.

想也许它会默认根据我本地分支的名称创建一个新的远程分支。输出是普通的推送输出,只有13个对象被推送。结果是难以察觉的。获取后,其他开发人员或我的本地存储库中没有任何新内容出现。

So what does git think I'm telling it to do when I do git push origin, and what effect, if any, did it have on my remote repo?

那么 git 认为我在执行时告诉它做什么git push origin,以及它对我的远程仓库有什么影响(如果有的话)?

回答by Sylvain Defresne

It depends on your git version. In old version, it would try to push each and every local branche that is also present on the distant side. Since version 1.6.3, the behaviour is controlled by the push.defaultconfiguration option.

这取决于你的 git 版本。在旧版本中,它会尝试推动也存在于远处的每个本地分支。从 1.6.3 版开始,行为由push.default配置选项控制。

Values are:

值是:

  • matching: [the default] push all branch with same local and distant name
  • nothing: push nothing
  • tracking: will only push the current branch if it is tracking a distant branch
  • current: will push current branch
  • matching: [默认] 推送具有相同本地和远程名称的所有分支
  • nothing: 什么都不推
  • tracking: 如果它正在跟踪远处的分支,只会推送当前分支
  • current: 将推送当前分支

回答by VonC

June 2012: [ANNOUNCE] Git 1.7.11.rc1

2012 年 6 月:[公告] Git 1.7.11.rc1

A new mode for push, "simple", which is a cross between "current" and "upstream", has been introduced.
"git push" without any refspec will push the current branch out to the same name at the remote repository only when it is set to track the branch with the same name over there.
The plan is to make this mode the new default value when push.default is not configured.

引入了一种新的push, " simple"模式,它是" current" 和 " upstream"之间交叉。没有任何 refspec 的
" git push" 会将当前分支推送到远程存储库中的同名分支,只有当它设置为跟踪那里的同名分支时
计划是在未配置 push.default 时将此模式设为新的默认值。



March 2012: Beware: that default "matching" policy might change soon
(sometime after Git1.7.10+)
:

2012 年 3 月:注意:默认的“匹配”策略可能很快就会改变
(Git1.7.10+ 之后的某个时间)

See "Please discuss: what "git push" should do when you do not say what to push?"

请参阅“请大家讨论:什么是‘混帐推’当你不说推我应该怎么办?

In the current setting(i.e. push.default=matching), git pushwithout argument will push all branches that exist locally and remotely with the same name.
This is usually appropriate when a developer pushes to his own public repository, but may be confusing if not dangerous when using a shared repository.

The proposal is to change the default to 'upstream', i.e. push only the current branch, and push it to the branch git pull would pull from.
Another candidate is 'current'; this pushes only the current branch to the remote branch of the same name.

What has been discussed so far can be seen in this thread:

在当前设置(即push.default=matching)中,git push不带参数将推送本地和远程存在的所有同名分支
当开发人员推送到他自己的公共存储库时,这通常是合适的,但在使用共享存储库时,如果没有危险,可能会造成混淆。

建议是将默认值更改为 ' upstream',即仅推送当前分支,并将其推送到 git pull 将从中拉出的分支。
另一个候选人是' current'; 这只会将当前分支推送到同名的远程分支。

到目前为止讨论的内容可以在这个线程中看到:

http://thread.gmane.org/gmane.comp.version-control.git/192547/focus=192694

http://thread.gmane.org/gmane.comp.version-control.git/192547/focus=192694

Previous relevant discussions include:

之前的相关讨论包括:

To join the discussion, send your messages to: [email protected]

要加入讨论,请将您的消息发送至:[email protected]