Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it a bad idea to hg update when your working copy has changes?

Tags:

mercurial

Seems like it would be better if you did commit followed by merge. I'm a little surprised update'ing is even allowed when your working copy has changes. Is allowing updates in such cases to avoid having commits that have two parents, which result from a merge?

like image 384
allyourcode Avatar asked Apr 16 '10 08:04

allyourcode


People also ask

What does hg update do?

Description. Update the repository's working directory to the specified changeset. If no changeset is specified, update to the tip of the current named branch and move the active bookmark (see hg help bookmarks). Update sets the working directory's parent revision to the specified changeset (see hg help parents).

What does hg revert do?

hg revert changes the file content only and leaves the working copy parent revision alone. You typically use hg revert when you decide that you don't want to keep the uncommited changes you've made to a file in your working copy.

How do I revert changes in mercurial?

Reverting Local Changes If you use the TortoiseHg client to work with Mercurial from TestComplete, you can cancel all local changes not committed to the repository yet: Select File > Source Control > Revert from the TestComplete main menu.

What is hg tip?

Use the hg heads command to list the heads of the current repository. The tip is the changeset added to the repository most recently. If you have just made a commit, that commit will be the tip. Alternately, if you have just pulled from another repository, the tip of that repository becomes the new tip.


2 Answers

I believe hg update will try to merge your uncommitted changes:

The following rules apply when the working directory contains uncommitted changes:

  1. If neither -c/--check nor -C/--clean is specified, and:
    if the requested changeset is an ancestor or descendant of the working directory's parent, the uncommitted changes are merged into the requested changeset and the merged result is left uncommitted.
    If the requested changeset is not an ancestor or descendant (that is, it is on another branch), the update is aborted and the uncommitted changes are preserved.
  2. With the -c/--check option, the update is aborted and the uncommitted changes are preserved.
  3. With the -C/--clean option, uncommitted changes are discarded and the working directory is updated to the requested changeset.

That will avoid an unnecessary commit (registered in the .hg repo) for an operation (hg update) which only is about updating your working directory.

like image 166
VonC Avatar answered Nov 13 '22 20:11

VonC


Mercurial encourages recording all the history of a project. If you've done some work in your working directory, why not to commit these changes providing a meaningful description of your results as a commit message and then merge your results into the main branch? It will be more clear for other people to see in two separate changesets what you have made as your normal work and what you have made just for resolving merge conflicts.

Usually an extra merge changeset is OK, but sometimes you just want to rebase your current changes on top of the main branch before committing them. You might take a look at the rebase extension. The new hg rebase command allows you to rebase already committed changeses.

like image 40
Andrey Vlasovskikh Avatar answered Nov 13 '22 19:11

Andrey Vlasovskikh