2012-01-16 28 views
2

讓我們說我有以下的配置文件將git拉自動合併,如果從_any_遠程拉?

[branch "master"] 
    remote = origin 
    merge = refs/heads/master 
[remote "origin"] 
    url = ssh://origin.com 
    fetch = +refs/heads/*:refs/remotes/origin/* 
[remote "faraway"] 
    url = ssh://faraway.com 
    fetch = +refs/heads/*:refs/remotes/faraway/* 

如果我這樣做git checkout master; git pull origin則:

  • fetch將運行
  • merge將合併獲取的分支我當前分支。

如果我運行git checkout master; git pull faraway,那麼git-merge會合並什麼?畢竟,我從遠程配置的遠程設備拔出。

回答

3

remote = origin指定當您處於分支中時拉(實際取指)的默認行爲。所以當你做git pull時,遙控器是原點(這也是默認的,即使遙控器沒有被指定,它也會從原點拉出來,如果指定了其他遙控器,那個遙控器將被取出。)

當你這樣做git pull faraway,將取回遙遠的分支,但不會合並(如遙遠的不是配置遠端),它在當前分支的主人,除非你做git pull faraway master

+0

當我試圖只指定一個非默認遠程(並沒有分支)我得到這個:'你要求從遠程'生產'拉,但沒有指定 分支。因爲這不是您當前分支的默認配置遠程 ,所以您必須在命令行上指定一個分支。「# – 2012-01-16 03:54:19

+0

@ Thr4wn - 是的,這不是我說的嗎?你必須做好'git pull far master' – manojlds 2012-01-16 03:58:43

+0

,我現在覺得很愚蠢; P那正是你所說的。 – 2012-01-16 04:01:41

0

git pull non-default-remote將返回

You asked to pull from the remote 'production', but did not specify 
a branch. Because this is not the default configured remote 
for your current branch, you must specify a branch on the command line. 

但是如果我輸入

git pull non-default-remote `git config remote.non-default-remote.fetch` 

然後它會自動與任何當前已簽出的遠程和完全忽略默認合併選項,因爲我是從一個非默認的遠程拉合併。