git merge master和origin/master之间的区别? [英] Difference between git merge master and 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
命令git merge master
的结果:
javanoob@DELL:~/workspace/PROJECT_One$ git merge master
Already up-to-date.
当我执行命令git merge origin/master
时,它表明有些文件将被覆盖,但是如果我执行相同的命令而没有前缀origin/
,则表示所有内容都是最新的.
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 fetch origin
I don't know if it matters but before running these commands, I did run the command git fetch origin
推荐答案
git fetch
获取远程分支上的信息,但不对本地master
分支进行任何更改.因此,master
和origin/master
仍然分开.您必须使用git pull
合并它们.
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
.
进行提交时,本地的master
分支在origin/master
之前,直到您推送这些更改.相反的情况是origin/master
分支位于本地master
分支之前.这就是为什么您获得不同结果的原因.
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.
阅读 https://stackoverflow.com/a/7104747/2961170 了解更多信息.
这篇关于git merge master和origin/master之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!