在 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 16:44:45  来源:igfitidea点击:

In Git, what is the difference between origin/master vs origin master?

git

提问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/masterorigin master 有什么区别。是否有一种明确的方式来理解何时使用origin/master以及何时应该使用origin master

回答by Dietrich Epp

There are actually three things here: origin masteris two separate things, and origin/masteris one thing. Three things total.

这里实际上有三件事:origin master是两件事,origin/master是一件事。一共三件事。

Two branches:

两个分支:

  • masteris a local branch
  • origin/masteris a remote branch (which is a local copyof the branch named "master" on the remote named "origin")
  • master是本地分支
  • origin/master是远程分支(它是名为“origin”的远程分支上名为“master”的分支的本地副本

One remote:

一个遥控器:

  • originis a remote
  • origin是遥控器

Example: pull in two steps

例子:拉入两步

Since origin/masteris a branch, you can merge it. Here's a pull in two steps:

由于origin/master是一个分支,您可以合并它。这里有两个步骤:

Step one, fetch masterfrom the remote origin. The masterbranch on originwill 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/masterinto master.

然后你合并origin/mastermaster.

git merge origin/master

Then you can push your new changes in masterback to origin:

然后,您可以将新更改推masterorigin

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/masteris an entity (since it is not a physical branch) representingthe state of the masterbranch on the remote origin.

origin/master是一个实体(因为它不是物理分支),表示master远程 上分支的状态origin

origin masteris the branch masteron the remote origin.

origin mastermaster遥控器上的分支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/masteris the remote masterbranch

origin/master是远程master分支

Usually after doing a git fetch originto 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/masteris referring to the remote branch, because you are basically telling GIT to rebase the origin/masterbranch onto the current branch.

通常在执行 agit fetch origin以从服务器带来所有更改之后,您将执行 agit rebase origin/master以重新设置更改并将分支移动到最新索引。这里,origin/master指的是远程分支,因为您基本上是在告诉 GIT 将origin/master分支重新定位到当前分支上。

You would use origin masterwhen pushing, for example. git push origin masteris simply telling GIT to push to the remote repository the local masterbranch.

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 masterbranch at origin.

鉴于这一事实,你可以切换到origin/master(虽然在分离状态),同时具有网络电缆被拔出,它必须是一个本地表示master在分支origin