I had a feature branch:
我有一个特征分支:
feature
with lets say 10 commits
让我们说10个提交。
then some time ago I started doing experiments on it, but wanted to preserve the current functionality just in case, so I started a new branch:
不久之前,我开始做实验,但想保留当前的功能以防万一,所以我开始了一个新的分支:
feature-experiment
and then did another 10 commits
然后又做了10个提交。
today I decided to merge
feature-experiment
into feature
and then I deleted feature-experiment
. There were some merge conflicts which I resolved.
今天,我决定将特性实验合并到特性中,然后删除了特性实验。我解决了一些合并冲突。
then, my 20 commits which were all using the same name and ending in WIP
(work in progress), were very ugly, so I decided to
然后,我的20个提交,它们都使用相同的名称,以WIP结尾(正在进行中的工作),非常丑陋,所以我决定。
git rebase -p -i HEAD~22
I changed pick
to s
to squash them all into the oldest commit for this feature, but I had some merge conflicts (the same as before). I resolved them and then
我改变了pick to s,把它们都塞进了这个特性中最古老的commit中,但是我有一些合并冲突(和以前一样)。我解决了他们。
git add -A && git commit
git rebase --continue
but now I get the following error:
但是现在我得到了以下错误:
error: Commit asd123qsd is a merge but no -m option was given.
fatal: cherry-pick failed
Could not pick asd123qsd
This is the last commit (the merge one)
这是最后一次提交(合并)
I tried again, but this time I didnt change this particular commit's pick
to s
, but got the same error.
我又试了一次,但是这次我没有把这个特定的commit改为s,而是得到了相同的错误。
How can I carry out this dreadful rebase?
我该如何执行这个可怕的基地?
I was thinking, as a possible solution, I could I modify the last commit to add -m to it, but how do I do that and what do I do with this -m command? Are there any other options
我在想,作为一个可能的解决方案,我可以修改最后一个提交,以添加-m,但是我该怎么做呢?我要怎么处理这个-m命令?还有其他选择吗?
1 个解决方案
#1
1
The problem is likely here:
问题很可能在这里:
git rebase -p -i HEAD~22
我的头~我的头~22。
The -p
option is described in the git documentation as the short version of --preserve-merges
:
在git文档中,-p选项被描述为短版本的—预先合并:
-p
- p
--preserve-merges
——preserve-merges
Recreate merge commits instead of flattening the history by replaying commits a merge commit introduces. Merge conflict resolutions or manual amendments to merge commits are not preserved.
重新创建合并提交,而不是通过重新播放提交合并提交来将历史变平。合并冲突决议或合并提交的手动修改没有保留。
This uses the --interactive machinery internally, but combining it with the --interactive option explicitly is generally not a good idea unless you know what you are doing (see BUGS below).
这在内部使用了交互式机器,但将其与交互式选项进行组合通常不是个好主意,除非您知道自己在做什么(参见下面的bug)。
Since you're trying to squash commits here, preserving merge commits is almost certainly not what you want. Additionally, the warning about combining the --preserve-merges
flag with the --interactive
(-i
) flag is likely relevant here.
既然您试图在这里挤压提交,那么保存合并提交几乎肯定不是您想要的。此外,在这里,将-preserve-merges标记与-交互式(-i)标志相结合的警告很可能是相关的。
Honestly though, using a rebase to do a squash like this may be introducing a lot more complexity than what you need here. If all you want is to squash all of the changes from this branch into a single commit, you can do that like this:
老实说,用一个rebase来做这样的壁球可能比你在这里所需要的要复杂得多。如果你想要把所有的变化从这个分支压缩成一个提交,你可以这样做:
git checkout feature
git reset --soft <base of feature branch>
At this point all the changes from your feature branch should be staged, and the feature branch should be at the base commit. Now you can simply run git commit
to create a new commit containing all the changes from your feature branch, which is basically equivalent to a squash.
此时,您的特性分支的所有更改都应该是分段的,并且特性分支应该在基本提交上。现在,您可以简单地运行git提交来创建一个新的提交,它包含了来自您的特性分支的所有更改,这基本上相当于一个壁球。
#1
1
The problem is likely here:
问题很可能在这里:
git rebase -p -i HEAD~22
我的头~我的头~22。
The -p
option is described in the git documentation as the short version of --preserve-merges
:
在git文档中,-p选项被描述为短版本的—预先合并:
-p
- p
--preserve-merges
——preserve-merges
Recreate merge commits instead of flattening the history by replaying commits a merge commit introduces. Merge conflict resolutions or manual amendments to merge commits are not preserved.
重新创建合并提交,而不是通过重新播放提交合并提交来将历史变平。合并冲突决议或合并提交的手动修改没有保留。
This uses the --interactive machinery internally, but combining it with the --interactive option explicitly is generally not a good idea unless you know what you are doing (see BUGS below).
这在内部使用了交互式机器,但将其与交互式选项进行组合通常不是个好主意,除非您知道自己在做什么(参见下面的bug)。
Since you're trying to squash commits here, preserving merge commits is almost certainly not what you want. Additionally, the warning about combining the --preserve-merges
flag with the --interactive
(-i
) flag is likely relevant here.
既然您试图在这里挤压提交,那么保存合并提交几乎肯定不是您想要的。此外,在这里,将-preserve-merges标记与-交互式(-i)标志相结合的警告很可能是相关的。
Honestly though, using a rebase to do a squash like this may be introducing a lot more complexity than what you need here. If all you want is to squash all of the changes from this branch into a single commit, you can do that like this:
老实说,用一个rebase来做这样的壁球可能比你在这里所需要的要复杂得多。如果你想要把所有的变化从这个分支压缩成一个提交,你可以这样做:
git checkout feature
git reset --soft <base of feature branch>
At this point all the changes from your feature branch should be staged, and the feature branch should be at the base commit. Now you can simply run git commit
to create a new commit containing all the changes from your feature branch, which is basically equivalent to a squash.
此时,您的特性分支的所有更改都应该是分段的,并且特性分支应该在基本提交上。现在,您可以简单地运行git提交来创建一个新的提交,它包含了来自您的特性分支的所有更改,这基本上相当于一个壁球。