mercurialmercurial-commit

Mercurial commit and merge


With Mercurial I often see a scenario where I need to gradually commit an push, but if another person commits in the middle of this then I get into a problem.

Example: Assume the HG repo has four files a.txt, b.txt, c.txt, d.txt and we have two users Mickey and Goofy:

Mickey does:  $ echo "change1" >> a.txt
Mickey does:  $ echo "change2" >> b.txt
Mickey does:  $ echo "change3" >> c.txt
Mickey does:  $ hg commit -m "I am good" a.txt
Goofy does:   $ hg pull -u; echo "change4" >> d.txt; hg commit -m "The Donald change" 

Mickey gets ready to commit and push, but has has to merge: Mickey does: $ hg pull -u

Now Mickey has two changes - in b.txt and c.txt. Lets assume that his changes in c.txt are complex and cannot be released just now. How can Mickey get his changes in a.txt and b.txt committed and pushed without committing c.txt yet?


Solution

  • Just issue the filenames you're interested in committing:

    hg commit a.txt b.txt -m'partial commit'
    

    Then push as usual.

    EDIT: Iyou could try saving the local changes as a patch, revert and pull the remote changes, then apply the patch:

    hg diff > local.patch
    hg revert
    hg pull -u
    patch -p1 < local.patch