在 Git 中,origin/master 与 origin master 之间有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18137175/
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
In Git, what is the difference between origin/master vs origin master?
提问by Senthil Kumaran
I know, originis a term for the remote repository and masteris the branch there.
我知道,origin是远程存储库的一个术语,master是那里的分支。
I am purposely omitting the "context" here and I am hoping that the answer should not depend upon the context. So in git command lines, what is the difference between origin/masterand origin master. Is there a non-ambiguous way to understand when to use origin/masterand when I should use origin master?
我在这里故意省略了“上下文”,我希望答案不应该取决于上下文。那么在 git 命令行中,origin/master和origin master 有什么区别。是否有一种明确的方式来理解何时使用origin/master以及何时应该使用origin master?
回答by Dietrich Epp
There are actually three things here: origin master
is two separate things, and origin/master
is one thing. Three things total.
这里实际上有三件事:origin master
是两件事,origin/master
是一件事。一共三件事。
Two branches:
两个分支:
master
is a local branchorigin/master
is a remote branch (which is a local copyof the branch named "master" on the remote named "origin")
master
是本地分支origin/master
是远程分支(它是名为“origin”的远程分支上名为“master”的分支的本地副本)
One remote:
一个遥控器:
origin
is a remote
origin
是遥控器
Example: pull in two steps
例子:拉入两步
Since origin/master
is a branch, you can merge it. Here's a pull in two steps:
由于origin/master
是一个分支,您可以合并它。这里有两个步骤:
Step one, fetch master
from the remote origin
. The master
branch on origin
will be fetched and the local copy will be named origin/master
.
第一步,master
从远程获取origin
。该master
分支上origin
会被获取并在本地副本将被命名为origin/master
。
git fetch origin master
Then you merge origin/master
into master
.
然后你合并origin/master
到master
.
git merge origin/master
Then you can push your new changes in master
back to origin
:
然后,您可以将新更改推master
回origin
:
git push origin master
More examples
更多例子
You can fetch multiple branches by name...
您可以按名称获取多个分支...
git fetch origin master stable oldstable
You can merge multiple branches...
您可以合并多个分支...
git merge origin/master hotfix-2275 hotfix-2276 hotfix-2290
回答by Femaref
origin/master
is an entity (since it is not a physical branch) representingthe state of the master
branch on the remote origin
.
origin/master
是一个实体(因为它不是物理分支),表示master
远程 上分支的状态origin
。
origin master
is the branch master
on the remote origin
.
origin master
是master
遥控器上的分支origin
。
So we have these:
所以我们有这些:
- origin/master ( A representation or a pointer to the remote branch)
- master - (actual branch)
- <Your_local_branch> (actual branch)
- <Your_local_branch2> (actual branch)
- <Your_local_branch3> (actual branch)
- origin/master(表示或指向远程分支的指针)
- master - (实际分支)
- <Your_local_branch>(实际分支)
- <Your_local_branch2>(实际分支)
- <Your_local_branch3>(实际分支)
Example (in local branch master
):
示例(在本地分支中master
):
git fetch # get current state of remote repository
git merge origin/master # merge state of remote master branch into local branch
git push origin master # push local branch master to remote branch master
回答by Raul Rene
origin/master
is the remote master
branch
origin/master
是远程master
分支
Usually after doing a git fetch origin
to bring all the changes from the server, you would do a git rebase origin/master
, to rebase your changes and move the branch to the latest index. Here, origin/master
is referring to the remote branch, because you are basically telling GIT to rebase the origin/master
branch onto the current branch.
通常在执行 agit fetch origin
以从服务器带来所有更改之后,您将执行 agit rebase origin/master
以重新设置更改并将分支移动到最新索引。这里,origin/master
指的是远程分支,因为您基本上是在告诉 GIT 将origin/master
分支重新定位到当前分支上。
You would use origin master
when pushing, for example. git push origin master
is simply telling GIT to push to the remote repository the local master
branch.
origin master
例如,您将在推送时使用。git push origin master
只是告诉 GIT 将本地master
分支推送到远程存储库。
回答by forvaidya
origin is a name for remote git url. There can be many more remotes example below.
origin 是远程 git url 的名称。下面可以有更多的遥控器示例。
bangalore => bangalore.example.com:project.git boston => boston.example.com:project.git
as far as origin/master (example bangalore/master) goes, it is pointer to "master" commit on bangaloresite . You see it in your clone.
就 origin/master (例如班加罗尔/master)而言,它是指向班加罗尔站点上的“master”提交的指针。你会在你的克隆中看到它。
It is possible that remote bangalore has advanced since you have done "fetch" or "pull"
自从您完成“获取”或“拉动”后,远程班加罗尔可能已经进步
回答by Martin
Given the fact that you can switch to origin/master
(though in detached state) while having your network cable unplugged, it must be a local representation of the master
branch at origin
.
鉴于这一事实,你可以切换到origin/master
(虽然在分离状态),同时具有网络电缆被拔出,它必须是一个本地表示master
在分支origin
。