我如何从远程跟踪分支中'git fetch'和'git merge'(如'git pull') [英] How Do I 'git fetch' and 'git merge' from a Remote Tracking Branch (like 'git pull')

查看:157
本文介绍了我如何从远程跟踪分支中'git fetch'和'git merge'(如'git pull')的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在git中设置了一些远程跟踪分支,但是我一旦用'git fetch'更新它们,似乎就无法将它们合并到本地分支中。



例如,假设我有一个名为'an-other-branch'的远程分支。我使用

  git branch --track an-other-branch origin / an-other-分行

到目前为止,这么好。但是,如果该分支得到更新(通常是通过移动机器并从该机器提交),并且我想在原始机器上进行更新,那么我会遇到取/合并问题:

  git fetch origin an-other-branch 
git merge origin / an-other-branch

每当我这样做时,我都会收到'已经最新的'消息,并且没有任何合并。

>然而,一个

  git pull源自其他分支

总是像你期望的那样更新它。

另外,运行git diff

  git diff origin / an-other-branch 

显示有差异,所以我认为我的语法错误。



我做错了什么?



编辑[2010-04-09]:我检查了几次,而且我绝对不在另一个分支上。我的'git fetch'后面跟着一个'git merge'(如上所示)是否与git pull完全相同?我会得到一些工作流程来显示git状态的结果等。 你不抓取分支,整个远程:

  git fetch origin 
git merge origin / an-other-branch


I have set up some remote tracking branches in git, but I never seem to be able to merge them into the local branch once I have updated them with 'git fetch'.

For example, suppose I have remote branch called 'an-other-branch'. I set that up locally as a tracking branch using

git branch --track an-other-branch origin/an-other-branch

So far, so good. But if that branch gets updated (usually by me moving machine and commiting from that machine), and I want to update it on the original machine, I'm running into trouble with fetch/merge:

git fetch origin an-other-branch
git merge origin/an-other-branch

Whenever I do this, I get an 'Already up-to-date' message and nothing merges.

However, a

git pull origin an-other-branch

always updates it like you would expect.

Also, running git diff

git diff origin/an-other-branch

shows that there are differences, so I think I have my syntax wrong.

What am I doing wrong?

EDIT [2010-04-09]: I have checked a couple of times, and I'm definitely not on a different branch. Should my 'git fetch' followed by a 'git merge' (as shown above) do the exact same thing as a git pull? I will get some workflow showing the results of a git status etc.

解决方案

You don't fetch a branch, you fetch an entire remote:

git fetch origin
git merge origin/an-other-branch

这篇关于我如何从远程跟踪分支中'git fetch'和'git merge'(如'git pull')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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