views:

83

answers:

2

I'm in the process of learning mercurial, and even though I installed TortoiseHG, I find myself turning more and more to the command line.

So often I would like to check what the result of a given hg command would be, before I actually run it, is there any equivalent to the -whatif switch known from powershell i can use, or how would you go about checking what would be committed using a given hg commit statement?

Regards Jesper Hauge

+1  A: 

Often the -n switch or --dry-run switch will show you what would have happened for a particular command. commit doesn't have an -n switch, but you could run hg diff to see the actual changes, or hg status to see what's going on with each file.

John Feminella
It seems to me that -n is only available for operations impacting remote repositories (e.g., push/pull). And so, there is no dry-run for "hg commit" because "hg rollback" allows to cancel it. Also there is no dry-run for "hg update" because you can always come back to an earlier version. So yes, I guess "hg status" and "hg diff" is the way to go to know what would be committed.
Christophe Muller
use `hg status` to get an overview and look at specific files with `hg diff <filename>`; a plain `hg diff` might be hard to read if a lot of files have changed
Christoph
+1  A: 

When you do commit your message editor will contain a list of files that will be committed in the ignored section. If you commit with hg -m "message" this won't work as the editor step is skipped:

HG: Enter commit message.  Lines beginning with 'HG:' are removed.
HG: Leave message empty to abort commit.
HG: --
HG: user: User <[email protected]>
HG: branch 'default'
HG: changed myfile.yxy

You can use hg commit and hg rollback to undo the last commit if it contained a file that you did not want to commit. The rollback works as long as you did not hg push to another repository.

Status works with the same patterns as commit. You can use hg status some/path/* and then hg commit some/path/* only replacing the command to use.

Thomas Jung
I'll try this method out, thanks for your answer!
Hauge