当我执行“pull -v --rebase=merges”且只有一次提交时,“变基 (1/4)”是什么意思?

Eug*_*kov 2 git

我有下一个提交:

* be23d923d (HEAD -> bot) Dump more info
* 506b1b5a7 (office/bot) Fix IP for registry.gitlab.office
* fb7e89677 Show build log on failure
*   58c2e3606 Merge branch 'implement_test' into test2
Run Code Online (Sandbox Code Playgroud)

运行后git pull -v --rebase=merges,结果为:

* 42852fd6b (HEAD -> bot) Dump more info
* a3c657c09 (office/bot) Echo $IMAGE_TAG
* 506b1b5a7 Fix IP for registry.gitlab.office
* fb7e89677 Show build log on failure
*   58c2e3606 Merge branch 'implement_test' into test2
Run Code Online (Sandbox Code Playgroud)

这是该命令的日志:

remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 2), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 287 bytes | 287.00 KiB/s, done.
From office-repo:office/bot
   506b1b5a7..a3c657c09  bot        -> office/bot
 = [up to date]          prod       -> office/prod
Changes from 506b1b5a7ebcf0e9778279f5de90bd67c0462e0a to a3c657c099ea0077a22d77de10029dd35be1058d:
 .gitlab-ci.yml | 1 +
 1 file changed, 1 insertion(+)
Rebasing (1/4)
Rebasing (2/4)
Rebasing (3/4)
 .gitlab-ci.yml | 1 +
 1 file changed, 1 insertion(+)
Successfully rebased and updated refs/heads/bot.
Run Code Online (Sandbox Code Playgroud)

我们可以看到远程仓库上只有on commit:

git log -w -b -p --ignore-blank-lines --full-history 506b1b5a7..a3c657c09
commit a3c657c099ea0077a22d77de10029dd35be1058d (office/bot)
Author: Administrator <admin@example.com>
Date:   Sun Dec 18 15:54:06 2022 +0000

    Echo $IMAGE_TAG

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 4ca4f8769..e4e25a947 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -23,6 +23,7 @@ build-job:
     - echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER $CI_REGISTRY --pass>
     - docker build -t $IMAGE_TAG .
     - docker push $IMAGE_TAG
+    - echo $IMAGE_TAG
 
 test-job1:
   stage: test
Run Code Online (Sandbox Code Playgroud)

当我期望有一个变基时,为什么会出现三个变基?Git 还忽略了最后一个 rebase 吗?
(显示1/4、2/4、3/4,没有Rebase 4/4

joa*_*nis 5

您在此处使用--rebase=merges,这意味着您的 pull 命令正在使用 agit rebase --rebase-merges来进行变基。

如果您仅使用它进行测试,git pull -v --rebase您将看到一个如您所期望的变基步骤。

但是,您可以使用 a来--rebase=merges分解它。它将让我们看到它将应用的变基步骤。git fetchgit rebase --rebase-merges -i office/bot-i

这是我在模拟案例中得到的结果:

label onto

reset onto
pick 2f840de bar
Run Code Online (Sandbox Code Playgroud)

这意味着 4 个变基指令。空行仍然被视为一条指令,但我确认它是:如果删除空行,变基日志将显示(n/3)而不是(n/4).

如果有任何合并,则需要这些额外的步骤来处理合并。在这种情况下,没有任何步骤,但步骤仍然存在,因为我猜git rebase --rebase-merges即使它看到没有合并,也不会优化它们。