gpt4 book ai didi

git - 当 merge 提交妨碍时如何避免 rebase hell ?

转载 作者:太空狗 更新时间:2023-10-29 13:17:39 25 4
gpt4 key购买 nike

我的 git 树中有以下情况:

1 -- 2 -- 3 -- 4 <-- master
\ \
5 -- 6 -- 7 -- 8 -- 9 <-- feature

我想对功能中的所有内容进行 rebase 和压缩,以便我可以通过一次提交添加的功能来推进掌握。

由于提交 7 已经是解决所有冲突的 merge ,我尝试了以下操作:

git rebase -i -p master

这里给我的唯一选项是提交 7、8 和 9。“有道理”,我想,“因为 merge 已经包括 5 和 6,所以它们可以被丢弃”。我在一次提交中压缩了 7、8 和 9,我们称之为“789”。 (我知道,我是创意类型。)

在此之后我的树看起来像这样:

1 -- 2 -- 3 -- 4 <-- master
\
5 -- 6 -- 789 <-- feature

5 和 6 在同一个分支中的存在让我感到困惑,但同样,由于它们已经包含在 7 中(现在在 789 中),我可以直接丢弃它们。

所以我再次 git rebase -i master 并且这次我丢弃了 5 和 6。

然而,这里那里出现了冲突,所以我放弃了整个事情。

我目前处于那个阶段,但我的远程分支尚未更新,所以我不妨重置为原始状态。

哪些是正确的步骤,可以让我到达我想要的位置,而无需手动解决所有 merge 冲突?

最佳答案

I want to rebase and squash everything from feature so that I can advance master with a single commit of the feature being added.

这正是 git merge--squash 选项做。来自docs for git merge :

--squash

Produce the working tree and index state as if a real merge happened (except for the merge information), but do not actually make a commit or move the HEAD, nor record $GIT_DIR/MERGE_HEAD to cause the next git commit command to create a merge commit. This allows you to create a single commit on top of the current branch whose effect is the same as merging another branch (or more in case of an octopus).

(强调我的)

使用示例:

git checkout master
git merge feature --squash
git commit

关于git - 当 merge 提交妨碍时如何避免 rebase hell ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24782116/

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