使用交互式变基,如何压缩一些提交,包括合并?
我在这里阅读了很多问题和帮助文档,但我似乎找不到任何可靠的、易于理解的文档来解释满足我的需求。
我所在的团队正在对代码进行重大更改。我们从“主”分支中分叉了一个分支。该分支是此功能工作的共享工作分支,我们将其称为“功能分支”。从这个二级分支,我们都为我们的个人工作分叉了新分支(例如“feature-branch-rlh”、“feature-branch-abc”等)。
在过去的几周里,我们都提交了一些工作到我们的分支机构并将该工作合并到“功能分支”中。此外,“feature-branch”已将“master”的一些工作合并到其中。
我们希望将过去两周的所有工作纳入“功能分支”,并将所有提交、合并和冲突修复压缩为一次提交。但是,我们想要保留从“master”合并的两个提交。我开始进行挤压的命令是这样的(其中 n 是要包含的提交数量):
git rebase --rebase-merges -i HEAD~n
我主要熟悉 git rebase,而不使用--rebase-merges
标志,但由于每次挤压时合并冲突解决方案似乎都会被忽略,因此我尝试将合并包含在挤压中。当我运行该命令时,而不是在交互式文件中看到类似这样的熟悉输出:
pick 11111111 Details
pick 22222222 Details
pick 33333333 Details
pick 44444444 Details
...
我现在看到如下所示的代码:
reset onto
pick 11111111
pick 22222222
pick 33333333
label branch-point-2
pick 44444444
label Merge-Commit
# Branch origin-feature-branch
reset branch-point-2
pick 55555555
label branch-point
pick 66666666
pick 77777777
merge -C 88888888 Merge-Commit # Merge Commit
pick 99999999
label origin-feature-branch-rlh
# Branch master
reset branch-point-2
pick aaaaaaaa Commit I want to keep, but not squash
label feature-branch
pick bbbbbbbb
merge -C cccccccc
pick dddddddd
...
这是我在交互式文件中看到的非常简化的提交列表。具体来说,我想要做的是将所有这些提交压缩到第一个提交(11111111)中。这包括用 merge -C
标记的合并提交(例如 88888888 和 cccccccc)。但是,提交 aaaaaaaa 之前有一个重置命令,我不想压缩它,我不知道该怎么做。
我怎样才能压缩所有适用的提交?我尝试重新排序我的列表,将 reset... pick... label...
代码放在文件末尾,而不是将其更改为 squash,但是由于我没有将
merge
更改为 squash
(老实说,我不知道我是否应该),有些东西似乎被破坏了。我一次又一次地遇到合并冲突,这些冲突已在以前的合并中得到修复。
我的最终目标是粉碎所有这些,除了一些提交。然而,无论我尝试什么,合并冲突都会继续阻碍,而这些冲突又在以前的合并中得到了修复。我需要做什么来解决这个问题?
I've read a LOT of questions on here and help documents, but I can't seem to find any solid, understandable documentation that explains addresses my needs.
I work on a team that's making a major code change. We forked a branch off of our 'master' branch. This branch is a shared working branch for this feature work which we'll call 'feature-branch'. From this secondary branch, we've all forked new branches for our personal work (e.g. 'feature-branch-rlh', 'feature-branch-abc', etc.)
Over the past couple of weeks, we've all committed some work to our branches and merged that work into 'feature-branch'. Also, 'feature-branch' has had some work merged into it from 'master'.
We want to take all of our work from the past two weeks within 'feature-branch' and squash all of the commits, merges and conflict fixes into one commit. However, we want to leave the two commits that were merged from 'master'. The command I start with for the squash is this (where n is the number of commits to include):
git rebase --rebase-merges -i HEAD~n
I am primarily familiar with git rebase without using the --rebase-merges
flag, but since merge conflict resolutions seem to be ignored every time I squash, I am trying to include the merges in the squash. When I run the command, instead of seeing familiar output like this in the interactive file:
pick 11111111 Details
pick 22222222 Details
pick 33333333 Details
pick 44444444 Details
...
I now see code that looks like this:
reset onto
pick 11111111
pick 22222222
pick 33333333
label branch-point-2
pick 44444444
label Merge-Commit
# Branch origin-feature-branch
reset branch-point-2
pick 55555555
label branch-point
pick 66666666
pick 77777777
merge -C 88888888 Merge-Commit # Merge Commit
pick 99999999
label origin-feature-branch-rlh
# Branch master
reset branch-point-2
pick aaaaaaaa Commit I want to keep, but not squash
label feature-branch
pick bbbbbbbb
merge -C cccccccc
pick dddddddd
...
This is a very simplified list of commits I see in the interactive file. Specifically, what I want to do is squash all of these commits into the first commit (11111111). This includes the merge commits (like 88888888 and cccccccc), that are marked with merge -C
. However, commit aaaaaaaa has a reset command before it, and I do NOT want to squash it and I'm not sure what to do.
How can I do squash all of the applicable commits? I've tried to re-order my list, putting the reset... pick... label...
code at the end of the file and not changing it to squash
, however since I don't change the merge
to a squash
(and honestly, I don't know if I should or not), something seems to be broken. I keep getting merge conflicts again and again, which have been fixed in former merges.
My end goal is to squash all of this, except for a couple of commits. However, no matter what I try, the merge conflicts keep getting in the way which, again, have been fixed in former merges. What do I need to do to solve this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论