- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我的 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/
我是一名优秀的程序员,十分优秀!