运行`git pull --rebase`,它会针对什么进行变基?

问题描述 投票:0回答:3

我看到很多例子:

git pull --rebase

但我想知道哪个分支被合并到当前分支中。不应该是

git pull --rebase <master>
git pull --rebase <dev>
吗?

git git-merge git-rebase git-pull
3个回答
3
投票

它首先获取

origin/theBranch
,然后在
origin/theBranch
之上重新调整您的更改。


带有草图:

  • 之前

    git pull --rebase

    *--*--*--*--A <- origin/theBranch
                 \
                  M--Y <- theBranch   # your local branch
    
  • git pull --rebase
    第 1 步:
    git fetch

    *--*--*--*--A--B--C--D <- origin/theBranch
                 \
                  M--Y <- theBranch
    
  • git pull --rebase
    步骤 2 :
    git rebase origin/theBranch

    *--*--*--*--A--B--C--D <- origin/theBranch
                          \
                           M'--Y' <- theBranch
    

0
投票

它将首先

git fetch
,就像
git pull
一样。然后,它不会运行
git merge
(这会从当前本地和远程分支创建合并提交),而是运行
git rebase
并重播对您正在其中工作的 当前本地分支 所做的更改。远程跟踪分支的最新提交。

git-pull - 从另一个存储库或本地获取并与其集成 分支。

git-rebase - 转发端口本地提交到更新的上游头。

现在,

git pull --rebase
=
git fetch
+
git rebase
反对追踪上游 分支

用例:假设您和您的队友正在同一分支上共同开发新功能。他做了一些更改并将其推送到远程。现在你需要获取并重新设置你的分支以合并他的更改。

您也可以使用

git pull --rebase <currentBranch>
代替
git pull --rebase

如果您明确想要将另一个分支更改合并到本地分支,那么您可以使用

git pull --rebase <otherBranch>


-3
投票

在使用其他人的存储库时,需要记住一些基本的 Git 命令:

git clone
git fetch
git merge
git pull

这些命令在与远程存储库交互时非常有用。

clone
fetch
将远程代码从存储库的远程 URL 下载到本地计算机。
merge
用于将不同人的工作与您的工作合并在一起,
pull
是 fetch 和 merge 的组合。

我们将在下面深入研究这些命令。

克隆

要获取其他用户存储库的完整副本,请使用 git clone ,如下所示:

git clone https://github.com/USERNAME/REPOSITORY.git

将存储库克隆到您的计算机

克隆存储库时,您可以从多个不同的 URL 中进行选择。登录 GitHub 后,可以在存储库详细信息下方找到这些 URL: 运行`git pull --rebase`,它会针对什么进行变基?

© www.soinside.com 2019 - 2024. All rights reserved.