gpt4 book ai didi

git - 如何在挑选多个补丁时跳过一个补丁?

转载 作者:行者123 更新时间:2023-12-05 04:03:55 24 4
gpt4 key购买 nike

我已经开始使用如下命令进行挑选:

git cherry-pick A B C D

假设补丁 A 和 B 存在一些 merge 冲突,但我最终修复了所有冲突并 git cherry-pick --continue。当我最终到达 C 时,我意识到必须已经应用了相同的代码,现在补丁是空的。

我可以选择 git cherry-pick --allow-empty 但这会在我的历史记录中留下一个我不想要的空提交。理想情况下,我只想跳过这个补丁 (C)。但是没有 git cherry-pick --skip。我可以 git cherry-pick --abort 但这会丢失我对 A 和 B 的所有工作。

作为一种解决方法,我可以接受空的,记住它是哪个,然后在完成 cherry-pick 后使用 git rebase -i B 将其删除。有没有更好的办法?

最佳答案

在 Git 2.23(2019 年第 3 季度)中,“git cherry-pick/revert”学习了一个新的“--skip”操作。

所以在你的情况下:git cherry-pick --skip on C

参见 commit dcb500d , commit de81ca3 , commit 265ab48 , commit 918d1e6 , commit 6a1f904 (2019 年 7 月 2 日)作者:Rohit Ashiwal (r1walz) .
(由 Junio C Hamano -- gitster -- merge 于 commit d97c62c ,2019 年 7 月 19 日)

cherry-pick/revert: add --skip option

git am or rebase have a --skip flag to skip the current commit if the user wishes to do so.

During a cherry-pick or revert a user could likewise skip a commit, but needs to use 'git reset' (or in the case of conflicts 'git reset --merge'), followed by 'git (cherry-pick | revert) --continue' to skip the commit.
This is more annoying and sometimes confusing on the users' part.

Add a --skip option to make skipping commits easier for the user and to make the commands more consistent.

Update the advice messages, to tell users about this less cumbersome way of skipping commits.

所以不是看到:

Otherwise, please use 'git reset

If you wish to skip this commit, use:

git reset

你会看到:

 Otherwise, please use 'git cherry-pick --skip

and then use:

git cherry-pick --continue

在 C 中重写“git rebase”期间,防止“git commit”在中断的 cherry-pick 期间进行空提交或修改的机制被破坏,已使用 Git 2.27(2020 年第二季度)更正。

参见 commit 5b7a64d (2019 年 12 月 6 日)Johannes Schindelin (dscho) .
参见 commit 430b75f , commit 901ba7b , commit 8d57f75 , commit 21b11c6 , commit f028d66 , commit 780308d (2019 年 12 月 6 日)Phillip Wood (phillipwood) .
(由 Junio C Hamano -- gitster -- merge 于 commit f085189,2020 年 3 月 25 日)

commit: give correct advice for empty commit during a rebase

Original-patch-by: Johannes Schindelin
Signed-off-by: Phillip Wood

In dcb500dc16c ("cherry-pick/revert: advise using --skip", 2019-07-02, Git v2.23.0-rc0 -- merge listed in batch #6), git commit learned to suggest to run git cherry-pick --skip when trying to cherry-pick an empty patch.

However, it was overlooked that there are more conditions than just a git cherry-pick when this advice is printed (which originally suggested the neutral git reset): the same can happen during a rebase.

Let's suggest the correct command, even during a rebase.

While at it, we adjust more places in builtin/commit.c that incorrectly assumed that the presence of a CHERRY_PICK_HEAD meant that surely this must be a cherry-pick in progress.

Note: we take pains to handle the situation when a user runs a git cherry-pick during a rebase.
This is quite valid (e.g. in an exec line in an interactive rebase).
On the other hand, it is not possible to run a rebase during a cherry-pick, meaning: if both rebase-merge/ and sequencer/ exist or CHERRY_PICK_HEAD and REBASE_HEAD point to the same commit , we still want to advise to use git cherry-pick --skip.

关于git - 如何在挑选多个补丁时跳过一个补丁?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53073010/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com