Git 重新定位:我们和他们的本地和远程

示例

重新设置基准将切换“我们的”和“他们的”的含义:

git checkout topic
git rebase   master    # rebase topic branch on top of master branch

HEAD指的是“我们的”

重新设置的第一件事是将重置HEAD为master;在从旧分支topic到新分支的樱桃采摘提交之前(前topic分支中的每个提交都将被重写,并由不同的哈希标识)。

关于合并工具使用的术语(不要与本地引用或远程引用混淆)

=> local is master ("ours"),
=> remote is topic ("theirs")

这意味着合并/差异工具会将上游分支显示为local(master:您要重新定基础的分支),将工作分支显示为remote(topic:正在重新定基础的分支)

+-----------------------------------------+
| LOCAL:master |    BASE   | REMOTE:topic |
+-----------------------------------------+
|             MERGED                      |
+-----------------------------------------+


反转说明

在合并中:

c--c--x--x--x(*) <- current branch topic ('*'=HEAD)
    \
     \
      \--y--y--y <- other branch to merge

我们不更改当前分支topic,因此所拥有的仍然是我们正在努力的工作(并且我们从另一个分支合并)

c--c--x--x--x---------o(*)  MERGE, still on branch topic
    \       ^        /
     \     ours     /
      \            /
       --y--y--y--/  
               ^
              theirs


在一个基础上:

但是在rebase上,我们会交换双方,因为rebase要做的第一件事是检出上游分支,以重播当前的提交!

c--c--x--x--x(*) <- current branch topic ('*'=HEAD)
    \
     \
      \--y--y--y <- upstream branch

Agit rebase upstream将首先设置HEAD到上游分支,因此与先前的“当前”工作分支相比,“我们的”和“他们的”的切换。

c--c--x--x--x <- former "current" branch, new "theirs"
    \
     \
      \--y--y--y(*) <- set HEAD to this commit, to replay x's on it
               ^       this will be the new "ours"
               |
            upstream

然后,rebase将在新的“我们的”topic分支上重放“他们”的提交:

c--c..x..x..x <- old "theirs" commits, now "ghosts", available through "reflogs"
    \
     \
      \--y--y--y--x'--x'--x'(*) <- topic  once all x's are replayed,
               ^                      point branch topic to this commit
               |
        upstream branch