What’s the easiest way to commit and push a single file while leaving other modifications alone?

It’s been almost 2 years since I originally posed this question. I’d do it differently now (as I mentioned in a comment above the question above). What I’d do now would be to instead commit my changes to the one file in my local repo (you can use the hg record extension to only commit pieces of a file):

hg commit -m "commit message" filename

Then just push out.

hg push

If there’s a conflict because other changes have been made to the repo that I need to merge first, I’d update to the parent revision (seen with “hg parents -r .” if you don’t know what it is), commit my other changes there so I’ve got 2 heads. Then revert back to the original single file commit and pull/merge the changes into that version. Then push out the changes with

hg push --rev .

To push out only the single file and the merge of that revision. Then you can merge the two heads you’ve got locally.

This way gets rid of the mq stuff and the potential for rejected hunks and keeps everything tracked by source control. You can also “hg strip” revisions off if you later decide you don’t want them.

Leave a Comment