git merge origin master 与 git merge origin/master 相同吗?

huangapple go评论62阅读模式
英文:

Is git merge origin master same as git merge origin/master?

问题

git merge origin mastergit merge origin/master 一样吗?如果不一样,有什么区别?目标是将最新的远程 master 合并到本地分支。

英文:

Is git merge origin master the same as git merge origin/master. If not how is it different? the objective is to merge the latest remote master to a local branch.

答案1

得分: 8

这完全不一样。git merge origin/master 会将你的远程跟踪分支 master 合并到当前的 HEAD。git merge origin master 会尝试创建一个八爪鱼合并,涉及到分支 originmaster 合并到当前的 HEAD。这可能会失败,因为很可能你并没有一个名为 origin 的分支(这将非常令人困惑,因为它是远程仓库的默认名称)。

使用 git merge origin/master

英文:

It is not the same at all. git merge origin/master will merge your remote-tracking branch master to your current head. git merge origin master will attempt to create an octopus merge with branches origin and master to the current head. It will probably fail, because most likely you do not have a branch named origin (which would be very confusing, since it is the default name for a remote repository).

Use git merge origin/master.

答案2

得分: 2

合并最新的master分支到当前origin的过程有两步。

  • 拉取(Fetch)
  • 合并(Merge)

可以通过不同的方式完成。逐步的方式是

git fetch origin
git merge origin/master

有一些方法可以在一定程度上_自动化_这个过程。其中之一是将origin/master设置为你正在处理的本地分支的_upstream_分支... 类似于 git branch --set-upstream-to=origin/master).... 然后你可以执行

git pull

git pull 会负责运行拉取然后合并。

另一种方式,如果你没有设置上游分支,可以执行

git pull origin master

这做的事情是一样的:拉取,合并。

英文:

Merging the latest from master as it is in origin right now is a 2-step process.

  • Fetch
  • Merge

This can be done in different ways. The step-by-step one is

git fetch origin
git merge origin/master

There are some things you can do to automate this process somewhat. One of them is to setup origin/master as the upstream branch of the local branch you are dealing with... something like git branch --set-upstream-to=origin/master).... then you can do

git pull

git pull takes care of running the fetch and then merging.

Another way, if you haven't set the upstream branch is to do

git pull origin master

Which does the same thing: fetch, merge.

huangapple
  • 本文由 发表于 2023年2月27日 15:29:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/75577745.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定