Git 仅将 HEAD 提交推送到 Gerrit,不包括之前精心挑选的提交

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

我精心挑选了一些更改,并且只想更新和推送顶级提交。然而,所有精选的提交也都在更新。例如,更改 444683 收到了一个带有注释的新补丁集:

Uploaded patch set 5: New patch set was added with same tree, parent tree, and commit message as Patch Set 4.
我不希望为之前精心挑选的提交创建新的补丁集。有没有办法防止这种情况发生?

$ git fetch ssh://review-project.myinc.com:29418/myprj/myprj-project refs/changes/83/444683/4 && git cherry-pick FETCH_HEAD
From ssh://git-project-lv.myinc.com:29418/myprj/myprj-project
 * branch                      refs/changes/83/444683/4 -> FETCH_HEAD
[main 2b6e920a0218] Test failure case 3
 Date: Fri Nov 8 06:17:37 2024 -0800
 1 file changed, 3 insertions(+)

$ git fetch ssh://review-project.myinc.com:29418/myprj/myprj-project refs/changes/40/449340/1 && git cherry-pick FETCH_HEAD
remote: Counting objects: 8958, done
remote: Finding sources: 100% (6371/6371)
remote: Total 6371 (delta 3429), reused 5218 (delta 3429)
Receiving objects: 100% (6371/6371), 18.74 MiB | 9.41 MiB/s, done.
Resolving deltas: 100% (3429/3429), completed with 750 local objects.
From ssh://git-project-lv.myinc.com:29418/myprj/myprj-project
 * branch                      refs/changes/40/449340/1 -> FETCH_HEAD
On branch main
Your branch is ahead of 'origin/main' by 1 commit.
  (use "git push" to publish your local commits)

You are currently cherry-picking commit 74726ac5a732.


$ git commit --allow-empty #-----------> I updated the commit message
[main 451839fba790] cherry-pick test for CUI
 Date: Mon Nov 18 10:09:47 2024 -0800

$ git log -1
commit 451839fba790e57f8255c96f6b626ccde3c98ce6 (HEAD -> main)
Author: Neth S <[email protected]>
Date:   Mon Nov 18 10:09:47 2024 -0800

    cherry-pick test

    Testing purpose

    Change-Id: I9c0fc86423ada538ad12072f2e6bb530f6dde258

$ git push origin 451839fba790e57f8255c96f6b626ccde3c98ce6:refs/for/main
Counting objects: 5, done.
Delta compression using up to 16 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 641 bytes | 641.00 KiB/s, done.
Total 5 (delta 3), reused 0 (delta 0)
remote: Resolving deltas: 100% (3/3)
remote: Processing changes: refs: 1, updated: 2, done
remote: warning: no changes between prior commit 526f331 and new commit 2b6e920
remote:
remote: SUCCESS
remote:
remote:   https://review-project.myinc.com/c/myprj/myprj-project/+/444683 Test failure case 3
remote:   https://review-project.myinc.com/c/myprj/myprj-project/+/449340 cherry-pick test
remote:
To ssh://review-project.myinc.com:29418/myprj/myprj-project
 * [new branch]                451839fba790e57f8255c96f6b626ccde3c98ce6 -> refs/for/main
git gerrit git-push
1个回答
0
投票

Git 不能只在推送时创建东西。您设置您想要的内容,然后推送它。

这需要重写历史。您可以选择基础分支顶部的顶部提交,或者更简单的方法是重新设置基数以删除其他提交。 5 次提交,您只想保留最后一项,对吗?

git rebase HEAD~ the-current-branch --onto HEAD~5
© www.soinside.com 2019 - 2024. All rights reserved.