Search code examples
version-controlmercurialbranching-and-mergingtortoisehg

Merge only some files/changesets between branches with Mercurial


Note: a similar question, Mercurial: Merging one file between branches in one repo, asks specifically about merging "only certain files, instead of whole changeset?" Contrary to that, I would be OK with merging certain changesets, not single files from a changeset.


I've got a VCS-related question for which I cannot find an answer (perhaps not googling the correct words). Maybe the whole idea is flawed. Please let me know.

Suppose in my version control repository I have two branches, default and feature. While working on the feature, I wrote a nice function foo.py. We decided to abandon the whole feature development, so the feature branch is going to be closed without merging into default. The files from feature should not appear in default, with one exception—we do want to keep the nice foo.py function, so it should appear in default.

Is it possible, without manipulating files off-VCS (which would cause history loss)? For example, could I somehow only merge the changesets where foo.py was created/modified?

A (realistic) variant of this situation is that foo.py was originally taken into feature from default. While working in feature, I modify foo.py. Now I want to abandon feature but have the modified foo.py in default.

Thanks a lot in advance!


Solution

  • A single changeset can be grafted onto another branch.

    This answer shows how to graft using thg.