Search code examples
version-controlmercurial

Update the working directory with part of a changeset


I've created a changeset which contains a number of individual changes. I've realized that one of those changes might not have been a good idea, and I'd like to update my working directory to include only part of that changeset to work on, without throwing out the changeset itself.

In git terms, I want to do something similar to git checkout -p HEAD~, or the similar

git checkout -b newbranch
git reset HEAD~
git add -p
git checkout -- .

How can I do this in Mercurial?


Solution

  • Read carefully hg help revert, pay special attention to -r option and NAME (ordinary list of fileset).

    In your case (single changeset, part of which you want to eliminate from Working Dir), you have to:

    • hg up to the this changeset
    • hg revert -r "p1(.)" set:SOME-FILESET or, instead of fileset ("set:PATTERN" part), just "... FILE FILE2 FILE3 FILEN"

    As result, you'll get in one readable command modified Working Directory with only needed part of changes in it