2012-11-19 66 views
3

我们使用github回购作为我们的“中央存储库”。git从特定分支拉到特定分支

我们计划有多个编码器以下列方式临时服务器上的工作:

  1. 编码人员对他们的本地回购一个单独的分支工作;
  2. 编码器推送改变github;然后
  3. 打码机拉从GitHub更新到服务器回购

因此,在实践中,在步骤3,编码器将运行在分期回购如下:

git checkout coderA-updates
git pull origin coderA-updates
git checkout master

有没有办法更新一个特定的分支,而不必先git checkout


TLDR: 你怎么做这样的事情git pull origin remoteBranch localBranch,而无需切换活跃的分支?

谢谢:)

+0

你的意思是“更新一个特定的分支”?其文件处于可用状态的唯一分支是已检出的当前分支。如果你想更新内部的回购,git fetch也会为其他分支做这件事,但是如果没有分支是最新的,你将无法处理这些文件。简而言之,您可以更新您想要的任何分支或所有分支,但只有当前分支的文件可用。 – eis

+0

嗨eis。通过“更新特定的分支”,我的意思是通过从github获取最新的提交来更新分支。我只想更新分支,我不需要这些文件可用。你如何使用git fetch来只更新一个特定的分支?谢谢 – Bibokid

回答

1
git checkout branchB 
git pull origin branchA 

这得到这发生在branchA变化并将它们合并成当地branchB

git help merge说:

Incorporates changes from the named commits (since the time their histories diverged from the current branch) into the current branch.

所以,我认为这是不可能不使当前的其中一人2个分支工作。

您可以在当前活动分支中使用git stash以保存更改,然后结账branchB并拉branchA。合并完成后,您签出您存储更改的分支并使用git stash apply

或者您可以简单地在检查/提取之前提交更改。

我希望这会有所帮助。

+0

谢谢sergey。这虽然改变了当前活动的分支。我想拥有它,以便当前活动的分支保持不变 – Bibokid

+0

我的问题是当有2个编码器拉动时。说编码器A在分支A上工作,编码器B在分支B上工作。当编码器A处于测试分支A的中间时,编码器B必须等到编码器A完成测试之后,才能将任何东西拉到分支B.谢谢btw :) – Bibokid

+2

@Bibokid你的意思是这两个编码器在同一个文件系统上工作?你能否澄清这个问题呢? – eis

0

git help pull

SYNOPSIS

git pull [options] [<repository> [<refspec>...]] 

DESCRIPTION

[...]

can name an arbitrary remote ref (for example, the name of a tag) or even a collection of refs with corresponding remote-tracking branches (e.g., refs/heads/:refs/remotes/origin/), but usually it is the name of a branch in the remote repository.

所以,你可以做git pull remoteBranch:localBranch,它会工作。

+0

谢谢,我会稍后再试 – Bibokid

+0

我尝试过'git pull origin remote remote:localBranch'但是错误:被拒绝(非fastforward)虽然我确定'localBranch'是'remoteBranch'的早期版本 – Bibokid

+0

尝试查看提交哈希。也许有一个'git rebase'或类似的东西影响了哈希。 – mgarciaisaia

0

使用普通fetch

git fetch origin remoteBranch:localBranch 

这只会默认快进的改变工作(见docs)。