git origin/branch_name 和 branch_name 之间的区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26125162/
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
difference between origin/branch_name and branch_name?
提问by stewart99
for pushing to bitbucket.
用于推送到 bitbucket。
If I do: git push origin origin/branch_name
my commits are not pushed.
如果我这样做:git push origin origin/branch_name
我的提交不会被推送。
Total 0 (delta 0), reused 0 (delta 0)
If I do git push origin branch_name
my commits are pushed:
如果我这样做,git push origin branch_name
我的提交会被推送:
Counting objects: 160, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (13/13), done.
Writing objects: 100% (20/20), 2.10 KiB | 0 bytes/s, done.
Total 20 (delta 6), reused 0 (delta 0)
so what is the origin/ mean in front of the branch_name? And why does it matter?
那么 branch_name 前面的起源/意思是什么?为什么这很重要?
回答by jub0bs
You have to keep in mind that there are different types of branches:
您必须记住,有不同类型的分支:
- (Purely) localbranches, i.e. branches you commit to,
- Branches that live in a remote repository, for lack of a better term. You may know the remote repository in question under a remote name, such as
origin
. From that repository's point of view, though, such a branch is local. Welcome to Distributed Version Control!:)
- Remote-trackingbranches. Also simply called remote branches, as in the Pro Git book, but I find this phrase confusing; remote-tracking branchis more accurate. They're special local branches whose sole purpose is to reflect the state of branches that live in a remote repositoryat the time of your last communication with the server. In particular, you can't commit to branches of this type.
- (纯粹)本地分支机构,即您承诺的分支机构,
- 由于缺乏更好的术语,位于远程存储库中的分支。您可能知道有问题的远程存储库以远程名称命名,例如
origin
. 但是,从该存储库的角度来看,这样的分支是local。欢迎使用分布式版本控制!:)
- 远程跟踪分支。也简称为远程分支,如Pro Git 书中的那样,但我觉得这句话令人困惑;远程跟踪分支更准确。它们是特殊的本地分支,其唯一目的是反映上次与服务器通信时位于远程存储库中的分支的状态。特别是,您不能提交到这种类型的分支。
Here, branch_name
is a localbranch, whereas origin/branch_name
is a remote-trackingbranch; it reflects the state of the corresponding branch that lives in origin
.
在此,branch_name
是一个本地分支,而origin/branch_name
是一个远程跟踪分支; 它反映了所在的相应分支origin
的状态。
Right after running
刚跑完
git fetch
the remote-trackingbranch origin/master
and the corresponding branch that live in origin
should be perfectly in sync (modulo concurrent pushes to the remote server, of course). It shouldn't be a surprise, then, that
所述远程跟踪分支origin/master
和相应的分支住origin
应该完全同步(模并发推到远程服务器,当然)。那么,这不应该是一个惊喜
git push origin origin/branch_name
doesn't push anything: you're essentially attempting to push stuff that is already present in the ancestry of the corresponding branch that live in origin
.
不推送任何内容:您实际上是在尝试推送已存在于origin
.
However, if your localbranch, branch_name
, is ahead by one or more commits,
但是,如果您的本地分支 ,branch_name
领先于一个或多个提交,
then running
然后运行
git push origin branch_name
will push the commits contained in branch_name
but not in the branch that live in origin
:
将推送包含在branch_name
但不在所在分支中origin
的提交:
回答by uml?ute
using a graphical tree viewer (like gitk --all
) will show you, that origin/mybranch
and mybranch
might differ.
使用图形树查看器(像gitk --all
)会告诉你,这origin/mybranch
和mybranch
可能有所不同。
origin
is just the defaultname for a cloned remote, which (in your case) contains a branch mybranch
(just like your local repository)
origin
只是克隆remote的默认名称,它(在您的情况下)包含一个分支(就像您的本地存储库一样)mybranch
so when you ask to push origin/mybranch
to origin
, you are synchronizing the origin
remote with itself, hence it doesn't do anything (luckily the remoteis always in synch with itself).
因此,当您要求 push origin/mybranch
to 时origin
,您正在将origin
遥控器与自身同步,因此它什么也不做(幸运的是遥控器始终与自身同步)。
the name origin
is arbitrary, and could have been set with the --origin
flag when cloning.
名称origin
是任意的,并且可以--origin
在克隆时使用标志设置。
回答by Claudio
origin/branch_name
is a branch on the remote machine- just
branch_name
is a branch on the local machine
origin/branch_name
是远程机器上的一个分支- 只是
branch_name
本地机器上的一个分支
回答by user583576
origin is whats stored remotely on github
origin 是远程存储在 github 上的内容
without origin is what is stored locally on your computer
没有来源是本地存储在您的计算机上的内容
when you commit 1st you are commit locally to your computer
当您第一次提交时,您将在本地提交到您的计算机
when you push origin branch name you are pushing to github
当您推送原始分支名称时,您正在推送到 github