How to merge only changes of certain files of a given changeset into a working copy?

Shridhar Daithankar ghodechhap at ghodechhap.net
Fri Feb 27 11:28:03 UTC 2009


On Friday 27 February 2009 15:43:32 Marko Käning wrote:
> having had a discussion with my favourite ClearCase user I came across a
> question which is most likely typical for CC:
>
> What if I want to merge only changes of a certain file (and not the whole
> directory or repository containg all files) in a given changeset into my
> current working copy?

Merge the changeset and revert the files you don't want. 

<untested code>
$ hg merge <rev>
$ hg revert `hg st|grep -v ^? |cut -f2 -d" "|grep -v <file to be retained>`
</untested code>

> I wonder whether I run into a conceptual problem here, typical for
> file-versioned SCM's like CVS or CC, or whether there is indeed a standard
> way to merge only singular files in hg.

Conceptually it is a problem. If a changeset adds a function in C++ 
header/sources, merging only the header will yield a non-compilable source 
tree.

OTOH that will demonstrate by example, why changeset based approach is better 
than tracking individual files :)

HTH
-- 
 Shridhar




More information about the Mercurial mailing list