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
Difference between git merge master and origin/master?
提问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/master
It 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 fetch
fetches information on remote branches, but does not make any changes to your local master
branch. Because of this, master
and origin/master
are 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 master
branch is ahead of origin/master
until you push those changes. This case is the opposite, where the origin/master
branch is ahead of your local master
branch. This is why you are getting different outcomes.
当您进行提交时,您的本地master
分支会提前,origin/master
直到您推送这些更改。这种情况正好相反,origin/master
分支机构领先于您当地的master
分支机构。这就是为什么你会得到不同的结果。
Read https://stackoverflow.com/a/7104747/2961170for more information.
回答by Vasfed
master
is your local branch, origin/master
is 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.txt
and 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 gup
for this) and only then proceed with merging.
所以 - 提交你的工作,检查 git 状态,然后做git pull --rebase
('oh-my-zsh' 有别名gup
),然后才继续合并。
回答by vauhochzett
Using git merge origin/master
refers to the master branch on the server. git merge master
refers to your local master branch.
usinggit merge origin/master
指的是服务器上的 master 分支。git merge master
指的是您当地的主分支。
By using git pull
you can merge them if they diverge.
通过使用,git pull
您可以在它们发散时合并它们。