为什么要在Git中匹配默认值? [英] Why is pushing to matching the default in Git?

查看:125
本文介绍了为什么要在Git中匹配默认值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于默认设置,Git将推送到'匹配'分支 - 名称相同的分支,而不是'上游'分支 - 被跟踪的分支。对我来说,切换到'上游'模式会更方便,因此我不必每次都指定我所推动的分支,但我认为'匹配'是默认的原因。有没有问题的设置为匹配,而不是上游设置将解决?

警告:push.default未设置;其隐式值在Git 2.0中发生变化


匹配表示git push会将所有本地分支推送到远程的同名分支上。这可以很容易地意外推送你不想要的分支。


这不是最佳实践:你不应该'将所有的分支推送到你的分支。

它们大多数可以是专门用于测试或内部开发的分支。


简单(Git 2.0默认)意味着 git push 会将仅当前分支推送到一个git pull会从中拉出来,并且检查他们的名字是否匹配。


默认情况下,它会推送您正在处理的分支,只有当分支存在于具有相同名称的远程端时(或如果你明确地创建它)。



你可以在[git push - 默认行为?]中找到关于该策略更改的更多讨论。2



我在 a>。




新的默认策略现在被合并到main( commit 289ca27 )并声明它是 commit 11037ee


我们承诺改变懒惰行为git push [there],它没有说在Git 2.0中将命令行从匹配推送到简单。

这最后翻转了那一点。


For the default setting, Git pushes to the 'matching' branch - the branch with the same name, rather than the 'upstream' branch - the branch being tracked. It would be more convenient for me to switch to the 'upstream' mode so that I don't have to specify each time what branch I am pushing too, but I assume 'matching' is the default for a reason. Are there any issues that having the setting as 'matching', rather than 'upstream' setting will resolve?

解决方案

As mentioned in "Warning: push.default is unset; its implicit value is changing in Git 2.0":

matching means git push will push all your local branches to the ones with the same name on the remote. This makes it easy to accidentally push a branch you didn't intend to.

And that is not a best practice: you shouldn't push all your branches.
Most of them can be private branches for test or internal dev only.

simple (Git 2.0 default) means git push will push only the current branch to the one that git pull would pull from, and also checks that their names match.

By default, it pushes the branch you are working on, only if said branch exists on the remote side with the same name (or if you create it explicitly).

You can find more discussion about that policy change in "[git push - Default behavior?].2".

I describe the other policies in "git - push current vs. push upstream (tracking)".


That new default policy is now merged to main (commit 289ca27) and states it is the new default in commit 11037ee:

We promised to change the behavior of lazy "git push [there]" that does not say what to push on the command line from "matching" to "simple" in Git 2.0.

This finally flips that bit.

这篇关于为什么要在Git中匹配默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆