Git - push.default“匹配”和“简单”有什么区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21839651/
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
Git - What is the difference between push.default "matching" and "simple"
提问by Josh
I have been using git for a while now, but I have never had to set up a new remote repo myself and I have been curious on doing so. I have been reading tutorials and I am confused on how to get "git push" to work.
我已经使用 git 一段时间了,但我从来没有必要自己设置一个新的远程仓库,我一直对这样做很好奇。我一直在阅读教程,但我对如何让“git push”起作用感到困惑。
If I simply use git push
it asks me to see up a default branch(?) to point to? What is the difference between these two options it supplies me with?
如果我只是使用git push
它会要求我查看要指向的默认分支(?)?它为我提供的这两个选项之间有什么区别?
git config --global push.default matching
git config --global push.default simple
Matching just pushes whatever branches I have on my local repo, and if they don't match I have to then manually tell it to push whatever new local branches I have, correct? Is this best practice to use or is simple best?
匹配只是推送我在本地仓库上的任何分支,如果它们不匹配,我必须手动告诉它推送我拥有的任何新本地分支,对吗?这是使用的最佳实践还是简单的最佳实践?
回答by Lalit Sachdeva
git push
can push all branches or a single one dependent on this configuration:
git push
可以根据此配置推送所有分支或单个分支:
Push all branches
推送所有分支
git config --global push.default matching
It will push all the branches to the remote branch and would merge them. If you don't want to push all branches, you can push the current branch only.
它将所有分支推送到远程分支并合并它们。如果不想推送所有分支,可以只推送当前分支。
Push only the current branch
只推送当前分支
git config --global push.default simple
So, it's better, in my opinion, to use this option and push your code branch by branch. It's better to push branches manually and individually.
因此,在我看来,最好使用此选项并逐个分支推送您的代码。最好手动和单独推送分支。
回答by UpAndAdam
From GIT documentation: Git Docs
来自 GIT 文档:Git Docs
Below gives the full information. In short, simple
will only push the current working branch
and even then only if it also has the same name on the remote. This is a very good setting for beginners and will become the default in GIT 2.0
下面给出了完整的信息。简而言之,只有当它在遥控器上也具有相同的名称时,simple
才会推送current working branch
。这对初学者来说是一个非常好的设置,并将成为默认设置GIT 2.0
Whereas matching
will push allbranches locally that have the same name on the remote. (Without regard to your current working branch ). This means potentially many different branches will be pushed, including those that you might not even want to share.
而matching
将在本地推送远程上具有相同名称的所有分支。(不考虑您当前的工作分支)。这意味着可能会推送许多不同的分支,包括那些您甚至可能不想共享的分支。
In my personal usage, I generally use a different option: current
which pushes the current working branch, (because I always branch for any changes). But for a beginner I'd suggest simple
在我个人的使用中,我通常使用不同的选项:current
推送当前工作分支,(因为我总是针对任何更改进行分支)。但对于初学者我建议simple
push.default
Defines the action git push should take if no refspec is explicitly given. Different values are well-suited for specific workflows; for instance, in a purely central workflow (i.e. the fetch source is equal to the push destination), upstream is probably what you want. Possible values are:nothing - do not push anything (error out) unless a refspec is explicitly given. This is primarily meant for people who want to avoid mistakes by always being explicit.
current - push the current branch to update a branch with the same name on the receiving end. Works in both central and non-central workflows.
upstream - push the current branch back to the branch whose changes are usually integrated into the current branch (which is called @{upstream}). This mode only makes sense if you are pushing to the same repository you would normally pull from (i.e. central workflow).
simple - in centralized workflow, work like upstream with an added safety to refuse to push if the upstream branch's name is different from the local one.
When pushing to a remote that is different from the remote you normally pull from, work as current. This is the safest option and is suited for beginners.
This mode will become the default in Git 2.0.
matching - push all branches having the same name on both ends. This makes the repository you are pushing to remember the set of branches that will be pushed out (e.g. if you always push maint and master there and no other branches, the repository you push to will have these two branches, and your local maint and master will be pushed there).
To use this mode effectively, you have to make sure all the branches you would push out are ready to be pushed out before running git push, as the whole point of this mode is to allow you to push all of the branches in one go. If you usually finish work on only one branch and push out the result, while other branches are unfinished, this mode is not for you. Also this mode is not suitable for pushing into a shared central repository, as other people may add new branches there, or update the tip of existing branches outside your control.
This is currently the default, but Git 2.0 will change the default to simple.
push.default
如果没有明确给出refspec,定义 git push 应该采取的行动。不同的值非常适合特定的工作流程;例如,在纯粹的中央工作流中(即获取源等于推送目标),上游可能就是您想要的。可能的值为:没有 - 除非明确给出 refspec,否则不要推送任何内容(错误输出)。这主要适用于希望通过始终明确避免错误的人。
current - 推送当前分支以更新接收端的同名分支。适用于中央和非中央工作流。
上游 - 将当前分支推回到其更改通常集成到当前分支中的分支(称为@{upstream})。此模式仅在您推送到您通常从中提取的同一存储库(即中央工作流)时才有意义。
简单 - 在集中式工作流程中,如果上游分支的名称与本地分支名称不同,则像上游一样工作,并增加安全性以拒绝推送。
当推送到与您通常拉出的遥控器不同的遥控器时,请作为当前使用。这是最安全的选择,适合初学者。
此模式将成为 Git 2.0 中的默认模式。
匹配 - 推送两端具有相同名称的所有分支。这使您推送的存储库记住将被推送出去的一组分支(例如,如果您总是将 maint 和 master 推送到那里而没有其他分支,则您推送到的存储库将具有这两个分支,以及您本地的 maint 和 master将被推到那里)。
为了有效地使用这种模式,你必须在运行 git push 之前确保你要推出的所有分支都准备好推出,因为这种模式的重点是允许你一次性推送所有分支。如果您通常只在一个分支上完成工作并推出结果,而其他分支未完成,则此模式不适合您。此外,此模式不适合推送到共享中央存储库,因为其他人可能会在那里添加新分支,或更新您无法控制的现有分支的提示。
这是当前的默认设置,但 Git 2.0 会将默认设置更改为 simple。
回答by CodeWizard
Git v2.0 Release Notes
Git v2.0 发行说明
Backward compatibility notes
向后兼容性说明
When git push [$there]
does not say what to push, we have used the
traditional "matching" semantics so far (all your branches were sent
to the remote as long as there already are branches of the same name
over there). In Git 2.0, the default is now the "simple" semantics,
which pushes:
什么git push [$there]
时候不说推送什么,到目前为止我们一直使用传统的“匹配”语义(只要那里已经有同名的分支,你的所有分支都被发送到远程)。在 Git 2.0 中,现在默认是“简单”语义,它推送:
only the current branch to the branch with the same name, and only when the current branch is set to integrate with that remote branch, if you are pushing to the same remote as you fetch from; or
only the current branch to the branch with the same name, if you are pushing to a remote that is not where you usually fetch from.
仅当前分支到同名分支,并且仅当当前分支设置为与该远程分支集成时,如果您要推送到与从中获取相同的远程;或者
只有当前分支到同名分支,如果你推送到一个不是你通常从那里获取的远程。
You can use the configuration variable "push.default" to change this. If you are an old-timer who wants to keep using the "matching" semantics, you can set the variable to "matching", for example. Read the documentation for other possibilities.
您可以使用配置变量“push.default”来更改它。例如,如果您是想继续使用“匹配”语义的老手,则可以将变量设置为“匹配”。阅读文档以了解其他可能性。
When git add -u
and git add -A
are run inside a subdirectory
without specifying which paths to add on the command line, they
operate on the entire tree for consistency with git commit -a
and
other commands (these commands used to operate only on the current
subdirectory). Say git add -u .
or git add -A .
if you want to
limit the operation to the current directory.
当git add -u
和git add -A
在子目录中运行而不指定在命令行上添加哪些路径时,它们对整个树进行操作以与git commit -a
和 其他命令(这些命令过去仅对当前子目录进行操作)保持一致。说git add -u .
或者git add -A .
如果您想将操作限制在当前目录。
git add <path>
is the same as git add -A <path>
now, so that
git add dir/
will notice paths you removed from the directory and
record the removal. In older versions of Git, git add <path>
used
to ignore removals. You can say git add --ignore-removal <path>
to
add only added or modified paths in <path>
, if you really want to.
git add <path>
与git add -A <path>
现在相同,因此
git add dir/
会注意到您从目录中删除的路径并记录删除。在旧版本的 Git 中,git add <path>
用于忽略删除。如果您真的想要,您可以说git add --ignore-removal <path>
只在 中添加添加或修改的路径<path>
。