git - 推送当前与推送上游(跟踪)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13751319/
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 - push current vs. push upstream (tracking)
提问by Eyal Golan
I have read the git man about push command, but I still don't understand the EXACT difference between currentand upstreamto be set in the push.default
我已经阅读了关于 push 命令的 git man,但我仍然不明白在push.default 中设置的current和upstream之间的确切区别
I want that our team will just do push, and only changes on the branch that they are currently working on, will be pushed. As I understand, this branch is the one that marked with * (star) when I do git branch.
我希望我们的团队只会推送,并且只会推送他们当前正在处理的分支上的更改。据我了解,这个分支是我在执行git branch时标有 * (星号)的分支。
Thanks for helping out.
感谢您的帮助。
回答by VonC
The question is whatare you pushing, and to where:
问题是你在推动什么,以及在哪里:
current
:- "what" is only your current branch (no other branches),
- "to where" is a branch of the same name (created if it doesn't exist) in the upstream repo.
upstream
:- "what" is also only the current branch,
- "to where" is to whatever branch (not necessarily of the same name) on the upstream repo has been assigned as an upstream branchfor the local branch you are pushing.
current
:- “ what”只是您当前的分支(没有其他分支),
- " to where" 是上游 repo中的同名分支(如果它不存在则创建)。
upstream
:
As explained here, Git2.0 will additionally introduce a new default for push.default
: simple
正如这里所解释的,Git2.0 将另外引入一个新的默认值push.default
:simple
simple
is like upstream
, but the upstream has to have the same name as well or the push will fail.
simple
就像upstream
,但上游也必须具有相同的名称,否则推送将失败。
Pushing only one branch (with the mode "simple
", "current
" or "upstream
") avoids the scenariowhere all matching branches are pushed (mode "matching
", which was the default for a long time), even though some of your branches might not be ready to be pushed.
只推送一个分支(使用模式“ simple
”、“ current
”或“ upstream
”)可以避免推送所有匹配分支的场景(模式“ matching
”,这是很长一段时间的默认模式),即使您的某些分支可能不是准备被推。
(master)> git push
...
To [email protected]:jkubicek/my_proj.git
21b430d..dd378ca master -> master
! [rejected] release -> release (non-fast-forward)
error: failed to push some refs to '[email protected]:jkubicek/my_proj.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart.
hint: If you did not intend to push that branch, you may want to
hint: specify branches to push or set the 'push.default' configuration
hint: variable to 'current' or 'upstream' to push only the current branch.
The difference between the two (current
and upstream
) is in the pull(what to pull from the remote to your branch?):
两者 (current
和upstream
)之间的区别在于拉取(从远程拉取什么到您的分支?):
pushing "
current
" doesn't mean that your current branchB
hasremote/B
has its upstream branch.
Ie:branch.B.merge
isn't set, when your are pushing the "current
" branch.
Ie: when pulling toB
, git won't know what branch to pull.pushing "
upstream
" means that your current branchB
hasremote/B
has its upstream branch.
Ie:branch.B.merge
isset, when your are pushing the "upstream
" branch.
Ie: when pulling toB
, git knows what branch to pull (as well as which remote repo:branch.B.remote
)
推“
current
”并不意味着你的当前分支B
具有remote/B
有其上游分支。
即:branch.B.merge
未设置,当您推动“current
”分支时。
即:拉到 时B
,git 不知道要拉哪个分支。推“
upstream
”指你当前分支B
具有remote/B
有其上游分支。
即:branch.B.merge
被设定,当你正在推动的“upstream
”分支。
即:牵引时B
,混帐知道什么分支拉(以及哪些远程回购:branch.B.remote
)
回答by Robert Siemer
push.default
is best covered in the man page of git config (man git-config
).
push.default
最好在 git config ( man git-config
)的手册页中介绍。
To understand the difference between “upstream” and “current” for push.default
, you should know the term upstream:
要了解 for 的“上游”和“当前”之间的区别push.default
,您应该了解上游一词:
Upstream is a local pointer from a normal local branch to a local remote-tracking branch. (Yes, these are all local.) Examples:
上游是从普通本地分支到本地远程跟踪分支的本地指针。(是的,这些都是本地的。)示例:
- branch blablahas origin/blablaconfigured as upstream (very common)
- branch blablahas origin/fooas upstream (branch has a different local name; not so common)
- branch blablahas origin2/fooas upstream
- 分支blabla将origin/blabla配置为上游(非常常见)
- 分支blabla将origin/foo作为上游(分支具有不同的本地名称;不太常见)
- 分支blabla将origin2/foo作为上游
Note that origin/*branches are local and (re-)set on each fetch from origin. These are called “local remote-tracking branches”. They represent the state of the branches on the remote “origin” at the time of the last fetch.
请注意,origin/*分支是本地的,并且在每次从原点获取时(重新)设置。这些被称为“本地远程跟踪分支”。它们代表最后一次获取时远程“原点”上分支的状态。
Each (normal) local branch can have an upstream configured, but this is no must: the configuration of an upstream relationship is only for convenience for some git commands!
每个(普通)本地分支都可以配置一个上游,但这不是必须的:上游关系的配置只是为了方便一些 git 命令!
If you do a git status
for example, git tells you “x commits behind/ahead” if it knows the upstream (so git can compare to it).
git status
例如,如果您执行 a ,git 会告诉您“x commits behind/ahead”,如果它知道上游(因此 git 可以与之进行比较)。
A normal initial git checkout blabla
usually sets up the upstream configuration for you (if origin/blabla exists, it is checked out and setup as upstream – otherwise the checkout fails).
一个普通的初始git checkout blabla
通常为你设置上游配置(如果 origin/blabla 存在,它被检出并设置为上游 - 否则检出失败)。
git push
can also use the upstream configuration of a branch, i.e. to copy your new commits over to the remote branch which represents upstream. (This is push.default = upstream
.)
git push
也可以使用分支的上游配置,即将您的新提交复制到代表上游的远程分支。(这是push.default = upstream
。)
push.default = current
lets a git push
copy the new commits over to the remote under the same name. It completely ignores the upstream configuration. – If your local branch name is always the same as the remote one, both configurations have the same effect, except that git push
with push.default = upstream
will fail, if upstream is not configured yet.
push.default = current
让我们以相同的名称git push
将新提交复制到远程。它完全忽略了上游配置。– 如果您的本地分支名称始终与远程分支名称相同,则两种配置具有相同的效果,但如果上游尚未配置,则with将失败。git push
push.default = upstream
PD: Yes, *
in the output of git branch
shows the current branch.
PD:是的,*
在输出中git branch
显示当前分支。