【问题标题】:git pull to different branch [duplicate]git拉到不同的分支[重复]
【发布时间】:2020-08-07 00:12:05
【问题描述】:

我正在开发一个功能分支,我的 master 分支设置为跟踪 origin/master。我想将更改从已合并的 origin/master 拉到 master 中,而不必从我的功能分支切换到 master。我该怎么做?

【问题讨论】:

  • git fetch origin master:master

标签: git pull


【解决方案1】:

我不相信真的有这样的 pull 选项,因为它是 git fetchgit merge 一个接一个。但是你可以做的是创建一个git alias 来为你做这件事。

您可以将其放入您的全局(或本地)gitconfig

[alias]
    pull-into = "!p() { git checkout $1 && git pull --rebase && git checkout - ; }; p"

这将创建一个git pull-into 别名,它只定义了一个名为p 的bash 函数。您将要从中提取的分支传递给它。它转到它,pull --rebase 就在上面(或者你可以只使用 git pull,如果你只是需要它)然后回到你以前的分支。

你可以像这样调用它,它会给出这样的输出

# currently on branch featurex
git pull-into master

Switched to branch 'master'
Your branch is behind 'origin/master' by X commits, and can be fast-forwarded.
  (use "git pull" to update your local branch) 
Updating 7699151..23b27bf
Fast-forward
<CHANGES AND SO ON>
Current branch master is up to date.
Switched to branch 'featurek'
Your branch is up to date with 'origin/featurex'.

【讨论】:

    【解决方案2】:

    您确定需要这样做吗?一个更常见的愿望是从master 的当前远程状态更新你的 分支。这是您无需离开分支机构即可轻松完成的事情:

    1. fetch 更新所有远程跟踪分支,包括origin/master

    2. merge origin/master(进入你当前的分支)——实际上我更喜欢变基,这取决于你

    现在master 的远程状态是您分支的一部分,因此差异最小化。这很可能是您的实际目标。

    猜你喜欢
    • 1970-01-01
    • 2013-04-07
    • 1970-01-01
    • 1970-01-01
    • 2021-03-11
    • 2014-05-24
    • 2021-03-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多