3

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!

texnic
  • 3,959
  • 4
  • 42
  • 75
  • 1
    Possible duplicate of [Mercurial: Merging one file between branches in one repo](https://stackoverflow.com/questions/1078881/mercurial-merging-one-file-between-branches-in-one-repo) – StayOnTarget Jul 13 '18 at 17:55
  • @DaveInCaz, the difference is that I don't want to split a changeset. I would be OK with taking whole changesets. – texnic Jul 14 '18 at 18:08
  • graft the single changeset? – Tom Jul 14 '18 at 20:36
  • @Tom I've never used graft. Will check it today! – texnic Jul 16 '18 at 07:11
  • @Tom, that was it! Can you please add it as a short answer? I think it's useful for others, to find the graft extension. – texnic Jul 16 '18 at 18:40

1 Answers1

1

A single changeset can be grafted onto another branch.

This answer shows how to graft using thg.

Tom
  • 6,325
  • 4
  • 31
  • 55