lcltj
lcltj

Reputation: 1598

How to partially merge branches in mercurial?

I have two branches in mercurial A and B, both of them have tests.py file but I don't want to merge those files when I merge A and B. How to ignore only tests.py and auto merge everything else?

Upvotes: 0

Views: 318

Answers (1)

bjlaub
bjlaub

Reputation: 2727

I don't believe there's a way to simply "ignore" the changes to a file when merging. What you can do is pick which version of tests.py (either the version from branch A or B) you want to go into the merge changeset and use that.

Since hg merge leaves the changes caused by merging two branches in your working copy, to give you a chance to fix up conflicts, etc, you can revert tests.py in the working copy before you commit to whichever version you'd like to keep. Here's an example:

$ hg update A   # switch to branch A
$ hg merge B    # merge w/ branch B
...
$ hg status
M tests.py
M some_other_file
...
# reset tests.py to version from either branch A or B.  
# Let's pick A since that was our original parent.
$ hg revert -r A tests.py
$ hg commit

Note that hg merge B might produce conflicts in tests.py, so if you use hg revert -r A tests.py you'd also need to mark the conflict as being resolved with hg resolve -m tests.py.

Upvotes: 4

Related Questions