重做已经提交的合并的一部分 [英] Redo part of an already committed merge
问题描述
如果这是在我合并之前发生的,我可以这样做:
$ b $ pre $ $ git checkout -m faulty_folder /
将错误的合并文件重置为其冲突状态,就像合并开始时一样。问题是我已经提交了合并,并且此命令似乎不再起作用。
简单的
$ git reset --soft HEAD ^
也不起作用。这确实从合并开始之前检出 HEAD ^
中的文件。
有没有办法回到那个合并状态?
更新
我不足以编辑文件到是正确的。如果可能的话,我会这样做的,但是我发现合并过于复杂。我需要再次获得3-way diff才能够可靠地解决冲突。
事实上,只需再次执行合并。 (请确保你关闭了 git rerere
)。
git merge
查看三件事情:您当前的提交,您要求它合并的提交以及这两个提交的合并基础。 (当然,也是你的策略论点等等,但你也可以重复这些)。确实,你已经提交了一个合并结果,但你仍然可以回到之前的提交: o --- o --- X < - otherbranch
/ \
...- -o - * \
\\
o - o - o - Y - M < - HEAD - > yourbranch
您的合并 M
是合并提交 Y
和 X
(合并基础 *
) 。但是你可以将提交 Y
作为分离的HEAD或新的分支。要创建一个新分支:
git checkout -b newbranch yourbranch ^
其中产生:
o --- o-- --X < - otherbranch
/ \
...-- o - * M < - yourbranch
\ /
o - o- -o - Y< - HEAD - > newbranch
(这是完全相同的图表,但我将 M
稍微腾出空间让 newbranch
指向提交 Y
- 有橡胶状/有弹性的,或在Play-Doh®上打印,或其他)。现在您可以 git merge otherbranch
并开始重新创建提交 M
。
现在您可以使用 git checkout yourbranch - path
来获取合并结果(而不是重新解析),以获得各种路径
s(甚至是顶部路径),并可选择 git checkout -m
零件重新创建冲突。
完成所有工作后, git commit
将创建一个新的 M2
合并,其第一个父元素为 Y
,第二个父母是 X
,并且 newbranch
会指向新的合并 M2
。
I have committed a big merge. Later, it appears that some files weren't merged correctly. I want to redo just these files, not the entire merge - the merge was big and I don't want to resolve all the conflicts that were correctly solved already.
If this had occurred before I committed the merge, I could do
$ git checkout -m faulty_folder/
to reset the faulty merged files to their conflicted state, just like when the merged was started. The problem is that I have committed the merge already, and this command doesn't seem to work anymore. A simple
$ git reset --soft HEAD^
doesn't work either. That really checks out files from HEAD^
, from before the merge was started.
Is there a way to go back to that merging state?
Update
It does not suffice for me to just edit the files to be correct. I would have done that if possible, but I find the merge to be too complicated for that. I need to get a 3-way diff again to be able to solve the conflicts reliably.
You can, in fact, simply perform the merge again. (Be sure you have git rerere
turned off.)
Remember, git merge
looks at three things: your current commit, the commit you ask it to merge, and the merge-base of those two commits. (Well, also your strategy arguments and so on, of course, but you can repeat those as well.) It's true that you already committed a merge result, but you can still get back on the commit you were on earlier:
o---o---X <-- otherbranch
/ \
...--o--* \
\ \
o--o--o--Y--M <-- HEAD -> yourbranch
Your merge M
is the result of merging commits Y
and X
(with merge base *
). But you can check out commit Y
as either a detached HEAD or a new branch. To make a new branch:
git checkout -b newbranch yourbranch^
which produces:
o---o----X <-- otherbranch
/ \
...--o--* M <-- yourbranch
\ /
o--o--o--Y <-- HEAD -> newbranch
(this is the exact same graph but I moved M
up a bit to make room for newbranch
to point to commit Y
—think of the graph as being kind of rubbery/stretchy, or printed on Play-Doh®, or whatever). Now you can git merge otherbranch
and start re-creating commit M
.
Now you can grab merge results (rather than re-resolving) using git checkout yourbranch -- path
for various path
s (even the top path), and optionally git checkout -m
parts to re-create conflicts.
When you are all done, git commit
will make a new M2
merge whose first parent is Y
and second parent is X
, and newbranch
will point to the new merge M2
.
这篇关于重做已经提交的合并的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!