merged two branches, and pushed, how to backout/strip?
Arne Babenhauserheide
arne_bab at web.de
Mon Jan 9 22:00:49 UTC 2017
Pierre-Yves David <pierre-yves.david at ens-lyon.org> writes:
> On 01/08/2017 10:55 PM, Arne Babenhauserheide wrote:
>> Uwe Brauer <oub at mat.ucm.es> writes:
>>> I merged a feature branch into default and pushed. I shouldn't have
>>> done. If that were a private repo, I would strip and that it is, but now
>>> how I am supposed to clean up the mess, the graph looks basically like
>>> this:
>>>
>>> @ changeset: 143:ec02f4c5e97e
>>> |\ tag: tip
>>> | | parent: 138:7e1a64287b87
>>> | | parent: 142:1dd731cf6a6a
>>> | | user: Uwe Brauer <oub at mat.ucm.es>
>>> | | date: Sun Jan 08 19:42:20 2017 +0000
>>> | | summary: Merged
>>> | |
>>> | o changeset: 142:1dd731cf6a6a
>>> | | branch: vs-11.89
>>> | | user: Uwe Brauer <oub at mat.ucm.es>
>>> | | date: Sun Jan 08 09:57:53 2017 +0000
>>> | | summary: Update Makefile and style/*.el
>>>
>>> 143:ec02f4c5e97e is the unwanted merge. I tried to rebase, but this was
>>> of course refused.
>>>
>>> I might update to the last commit in the default branch, add stuff
>>> commit and push creating a new head, but are there better solutions?
>>
>> If the code being in the open is no problem, you can always revert
>> default to the commit before the merge, then commit, then merge default
>> into vs-11.89, revert vs-11.89 to the other commit before the merge and
>> commit again.
>>
>> hg revert --all -r 138:7e1a64287b87
>> hg commit -m "backout bad merge"
>> hg up vs-11.89
>> hg merge default
>> hg ci -m "merge default with the backout"
>> hg revert --all -r 142:1dd731cf6a6a
>> hg ci -m "backout the backout"
>>
>> Now from the view of hg, everything should work the same way as before
>> (including later merges into default and later merges of default into
>> vs-11.89).
>
> That's a convoluted but smart way to work around the "we can't backout
> merge" core limitation of how DVCS dags work.
>
> Currently the help says:
>
> Note:
> 'hg backout' cannot be used to fix either an unwanted or
> incorrect merge.
>
> Arne, would you mind provide a more detailed explanation of why backing
> out merge is problematic and how to execute your work around (and maybe
> even automate it withing the backout command, but I'm not too excited
> about that yet). That documentation update could be either on the wiki
> or directly in the inline help if you find a non-scary way to put that
> down.
>
> What do you think ?
Finding a non-scary way to put this seems pretty hard.
The gist is that you need to undo the merge in both branches.
But I can provie automated instructions.
## backout merge
MERGEREV=$(hg id -q)
p1=$(hg log -T "{parents}" -r ${MERGEREV} | cut -d " " -f 1)
p2=$(hg log -T "{parents}" -r ${MERGEREV} | cut -d " " -f 2)
# target branch:
hg up ${MERGEREV}
hg revert --all -r ${p1}
hg ci -m "backout merge on branch $(hg log -r . -T '{branch}')"
hg diff -r . -r ${p1} # empty diff!
# source branch:
hg up ${p2}
hg merge tip
hg ci -m "merge backout into branch $(hg log -r ${p2} -T '{branch}')"
hg revert --all -r ${p2}
hg ci -m "backout backout from branch $(hg log -r ${p1} -T '{branch}')"
hg diff -r . -r ${p2} # empty diff!
# check the log
hg log -G
This should do the right thing for any MERGEREV.
(using the repo from Uwe as starting point:
hg init
echo Main1 > main.txt
hg add main.txt
hg commit -m "Main1"
echo Main2 >> main.txt
hg commit -m "Main1"
hg branch vs-11.89
echo branch1 > main.txt
hg commit -m "Good Commit1"
echo branch2 >> main.txt
hg commit -m "Good Commit2"
echo badvariable >> main.txt
hg commit -m "Bad Commit"
# back to the default branch
hg up default
hg merge vs-11.89
hg commit -m "Bad merge"
# check the log
hg log -G
)
Best wishes,
Arne
--
Unpolitisch sein
heißt politisch sein
ohne es zu merken
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 800 bytes
Desc: not available
URL: <http://lists.mercurial-scm.org/pipermail/mercurial/attachments/20170109/b0bcb804/attachment.asc>
More information about the Mercurial
mailing list