开发者

Reverting "discard all changes" merge effect

开发者 https://www.devze.com 2023-03-02 22:49 出处:网络
Let\'s suppose it was performed merge with \"Discard all changes from merge ...\" option, bu accident.

Let's suppose it was performed merge with "Discard all changes from merge ..." option, bu accident.

And this wrong commit has been committed into the "central" repository.

How to deal with this case if I need to merge in correct way the branch changes?

Commands to reproduce the case:

hg init mr
cd mr

echo "123" > file.txt
hg add
hg ci -m "initial"

hg branch br
echo "234" >> file.txt
hg ci -m "in branch"

hg up default
echo "567" >> file.txt
hg ci -m "in default"

After these commands open tortoisehg, and merge 2nd revision (default head) with 开发者_如何学Cbr branch with "Discard ..." option.

UPD:

It is a question about doing the opposite How to merge to get rid of head with Mercurial command line, like I can do with TortoiseHg? ;-)

But still cannot find how to revert that step :-(


One way would be to redo the merge, and do yet another merge with discard.

In your example, update back to the 2nd revision (the current working directory parent before you did the bad merge), then redo the merge with that other branch. Do it properly this time.

This will give you another head.

Then, merge with the old, incorrect merge, and choose discard on this. Now you have effectively bypassed this merge with a correct one.

If you're unsure about the steps, make a local clone and experiment, you can always just discard it and reclone and try again.

Revision 3 is the old, incorrect merge, where I chose discard. After doing merge 4 and 5, the traces of that merge is gone and everything is back in working order. Yes, the history looks a little funky, but trust me, the cleanup procedures to get rid of that bad merge completely is far worse than the little hickup on your history timeline.

Basically you have this scenario after the botched merge:

            +-- botched merge
            v
    0---2---3
     \     /
      1---+

So you update back to the working folder parent you had before the bad merge, and do another merge, this time properly. Now it looks like this:

            +-- botched merge
            v
    0---2---3
     \   \ /
      \   x
       1-+-4
           ^
           +-- good merge

Your working folder is now at revision 4, so you do yet another merge, this time with revision 3 (the bad merge), and choose to discard those changes, and you get this:

            +-- botched merge
            v
    0---2---3-5  <-- final merge, discard 3
     \   \ / /
      \   x /
       1-+-4
           ^
           +-- good merge

Here's how TortoiseHg shows this:

Reverting "discard all changes" merge effect

0

精彩评论

暂无评论...
验证码 换一张
取 消