git merge master和origin/master之间的区别? [英] Difference between git merge master and origin/master?

查看:589
本文介绍了git merge master和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分支进行任何更改.因此,masterorigin/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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆