首要要保证本地代码是提交得,git status查看,还没的话就add-commit一下再开始拉取。
两种方法都行:
方法一:拉取到新得分支再对比合并
1.查看远程分支
$ git remote -v
2.从远程获取最新版本到本地,创建一个新的分支叫做temp
$ git fetch origin master:temp
3.比较本地仓库与下载的temp分支
$ git merge temp
4.删除不要的分支
$ git branch -D temp
方法二:pull
git pull的作用是,从远程库中获取某个分支的更新,再与本地指定的分支进行自动merge
$ git pull <远程库名> <远程分支名>:<本地分支名>
比如,取回远程库中的develop分支,与本地的develop分支进行merge,要写成:
git pull origin develop:develop
如果是要与本地当前分支merge,则冒号后面的<本地分支名>可以不写。
git pull origin develop
通常,git会将本地库分支与远程分支之间建立一种追踪关系。比如,在git clone的时候,所有本地分支默认与远程库的同名分支建立追踪关系。也就是说,本地的master分支自动追踪origin/master分支。因此,如果当前处于本地develop分支上,并且本地develop分支与远程的develop分支有追踪关系,那么远程的分支名可以省略:
git pull origin
其实,git pull 命令等同于先做了git fetch ,再做了git merge。即:
git fetch origin develop
git checkout develop
git merge origin/develop
或者
git fetch origin master:temp
git diff temp
git merge temp
git branch -d temp
好多人不建议使用git pull,喜欢自己merge,以便万一自动merge出错的时候可以解决冲突