Sunday, October 14, 2012

Mercurial - Diff or Log?

You want to see a list of files that were changed in the last changeset?

Some people will say that is a diff, others would argue that purely listing the changed files is not a diff.

hg log -v -r e64f09773235

Grep loving sysadmins might also use:

hg diff -c e64f09773235 | fgrep 2012

But now I want to peek backwards in time to see what the file looked like before and after:

hg parents
hg cat wsgi/ -r 1

hg cat wsgi/ -r 0

hg diff is probably an easier way of seeing differences between files,
but I use hg cat here to illustrate its use.

Notes and repository for the examples:

Note that, at no point, did I alter the files on the local filesystem.
And the state of my local mercurial repository was never altered.

Essentially I am querying the history to get what I want.

Had I issued hg update 0 then I would have reverted my local state back to the first commit. Then I could directly inspect the file wsgi/

However the point of having a log is to support exactly this sort of querying without necessarily changing local state.

Based on what you find, you may then choose to change local state, but in the first instance you have querying tools that are non-disruptive, which is nice :)

Want to follow along and experiment?
Start by cloning the repository, and then follow my commands from the top of the article.

Cloning - use either of the command below:
  • hg clone
  • hg clone ssh://

No comments: