Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Breaking the file connection in Mercurial after bad file split

Tags:

mercurial

Background:

At first there was a file base.c, and that file was in the repository which had only one branch Base.

Base was branched to make Extended-branch. Then this new branch had several changes made to base.c.

If bugs were fixed in file base.c in Base, they would be merged to Extended.

It turns out that adding too much stuff to base.c in Extended branch was not a good idea, so file is copied to ext.c. Then most of the Extended additions are removed from base.c, and Base functionality from ext.c. So at this point base.c in Extended is very similar as in Base.

Problem:

When file was split, Mercurial was informed that ext.c is a copy of base.c, because they shared a common history. Unfortunately this was not a good idea.

Now if bugs are fixed on Base branch and merged to Extended, Mercurial thinks that those changes should be applied to both base.c and ext.c, even though the latter is no longer has any similarities to former. This makes the merges very annoying.

Is there a way to tell the Mercurial that ext.c should no longer be considered same as base.c? One solution would be to replace ext.c with new file, but then history would not follow.

like image 506
user694733 Avatar asked Jun 05 '13 05:06

user694733


1 Answers

You can break the connection with hg forget ext.c, and then hg add ext.c as a new file. But if you do this with the tip revision of ext.c, you'll lose all history up to this point.

What you can do instead is to add an earlier version of ext.c, maybe even from before the rename, and replay (graft) its history since then. You could add the history of ext.c as a branch to a past revision, and merge it into tip:

---o---o---o---(tip)--(merge)
    \                /
     e---e---e ...  e

Or perhaps it doesn't matter, and you can just add the history of ext.c to the current tip:

---o---o---o---(tip)--e--e--e--e

Neither of these approaches involves any history rewriting (the "forgotten" version of ext.c is just left as a dead end), so there should be no problems with propagating changes.

like image 67
alexis Avatar answered Oct 03 '22 05:10

alexis