Git推送问题 - Pedantic

4
我有一个主分支和一个搜索功能分支在我的项目中。我已经将搜索功能分支推送到远程仓库,到目前为止都很好。
今天早上我在那个分支上工作时,我执行了“git push”命令,结果得到以下提示:
warning: You did not specify any refspecs to push, and the current remote
warning: has not configured any push refspecs. The default action in this
warning: case is to push all matching refspecs, that is, all branches
warning: that exist both locally and remotely will be updated.  This may
warning: not necessarily be what you want to happen.
warning: 
warning: You can specify what action you want to take in this case, and
warning: avoid seeing this message again, by configuring 'push.default' to:
warning:   'nothing'  : Do not push anything
warning:   'matching' : Push all matching branches (default)
warning:   'tracking' : Push the current branch to whatever it is tracking
warning:   'current'  : Push the current branch

所以我执行了git config push.default tracking命令,然后git push就可以正常工作了,没有问题,也没有警告。

我不理解"current"和"tracking"之间的区别是什么,如果你不将其“跟踪到任何地方”,那么“current”的意义是什么——它会去哪里?在哪些情况下会使用current而不是tracking?

此外,有哪些情况下会使用“nothing”?

1个回答

6
Git1.6.3以来:
当用户没有告诉“git push”要推送什么时,它总是会推送匹配的引用。对于一些人来说,这是意外的,因此引入了一个新的配置变量push.default,允许更改不同的默认行为。为了宣传这个新功能,在未配置并尝试使用git push而不带参数时,会发出一个大的警告。
所以当前和追踪之间的区别在于:
- 当前将假定匹配的引用(具有相同名称的远程分支,可能不存在) - 追踪将基于与该本地分支关联的追踪引用使用的远程引用。如果它没有跟踪任何内容,则不会推送。但它可以跟踪具有不同名称的远程分支。
注意:default nothing对于只用于内容咨询的只读存储库非常有用,其中不应进行任何工作并在任何地方发布。

另请参阅git push current branch SO问题。


2012年3月更新:注意:默认的“匹配”策略可能很快会改变:

请参见 "请讨论:当您没有说明要推送什么时,“git push”应该做什么?"

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

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

到目前为止已经讨论的内容可以在此线程中查看:

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

之前的相关讨论包括:

要参与讨论,请将您的消息发送至:git@vger.kernel.org


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