git merge master 和 origin/master 之间的区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34496806/
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-09 03:47:26  来源:igfitidea点击:

Difference between git merge master and origin/master?

git

提问by javanoob

Result of the command git merge origin/master:

命令的结果git merge origin/master

javanoob@DELL:~/workspace/PROJECT_One$ git merge origin/master 
Updating d83ef9c..dd520ea
error: The following untracked working tree files would be overwritten by merge:
    sample.txt
Please move or remove them before you can merge.
Aborting

Result of the command git merge master:

命令的结果git merge master

javanoob@DELL:~/workspace/PROJECT_One$ git merge master
Already up-to-date.

When I do the command git merge origin/masterIt shows that there are some files which will be overwritten but if I do the same command without the prefix origin/it says everything is already up-to-date.

当我执行命令时,git merge origin/master它显示有一些文件将被覆盖,但是如果我执行没有前缀的相同命令,origin/它表示一切都已经是最新的。

What is wrong in this setup?

这个设置有什么问题?

I don't know if it matters but before running these commands, I did run the command git fetch origin

我不知道这是否重要,但在运行这些命令之前,我确实运行了命令 git fetch origin

回答by fisk

git fetchfetches information on remote branches, but does not make any changes to your local masterbranch. Because of this, masterand origin/masterare still diverged. You'd have to merge them by using git pull.

git fetch获取有关远程分支的信息,但不对本地master分支进行任何更改。正因为如此,master并且origin/master仍然分歧。您必须使用git pull.

When you make a commit, your local masterbranch is ahead of origin/masteruntil you push those changes. This case is the opposite, where the origin/masterbranch is ahead of your local masterbranch. This is why you are getting different outcomes.

当您进行提交时,您的本地master分支会提前,origin/master直到您推送这些更改。这种情况正好相反,origin/master分支机构领先于您当地的master分支机构。这就是为什么你会得到不同的结果。

Read https://stackoverflow.com/a/7104747/2961170for more information.

阅读https://stackoverflow.com/a/7104747/2961170了解更多信息。

回答by Vasfed

masteris your local branch, origin/masteris remote branch (the state it was at last fetch)

master是你的本地分支,origin/master是远程分支(它最后的状态fetch

The output you have shows that there's a commit in remote, that will overwrite sample.txtand is not yet pull'ed into your local master

您的输出显示远程有一个提交,它将覆盖sample.txt并且尚未pull进入您的本地master

As a rule of thumb - it's always better to have a clean working tree and up-to-date branches before doing any merging/rebasing etc.

根据经验 - 在进行任何合并/重新定位等之前,最好拥有一个干净的工作树和最新的分支。

So - commit your work, check git status, then do git pull --rebase('oh-my-zsh' has alias gupfor this) and only then proceed with merging.

所以 - 提交你的工作,检查 git 状态,然后做git pull --rebase('oh-my-zsh' 有别名gup),然后才继续合并。

回答by vauhochzett

Using git merge origin/masterrefers to the master branch on the server. git merge masterrefers to your local master branch.

usinggit merge origin/master指的是服务器上的 master 分支。git merge master指的是您当地的主分支。

By using git pullyou can merge them if they diverge.

通过使用,git pull您可以在它们发散时合并它们。