Search code examples
mercurialtortoisehg

In Mercurial how do I extract a single file's changes from a Changeset to apply to another branch?


I have a large commit of many files on one branch, I need to transfer the modifications of a single file in that changeset to another branch. How can I do this? I am mostly using TortoiseHg but commandline solutions are also fine.

If I go to the changeset in TortoiseHg and select the file I can see the diffs I want to transfer, but not a way to actually apply them.


Solution

  • You can get the patch for just that file using:

    hg log -r THEREVISIONWITHLOTSOFCHANGES -p -I path/to/justthatfile > justthatfile.patch
    

    which you can then import on whatever branch you want by doing:

    hg update anotherbranch
    hg import --no-commit justthatfile.patch
    hg commit