esther h
esther h

Reputation: 1468

Mercurial - how to see the history for a specific line of code

I have a CSS file with thousands of lines of code. I want to see when a specific line/chunk of code was changed, without going back and reviewing each revision that changed this file (that will take a looooong time!)

Is there a way, using either TortoiseHg, Eclipse with a Mercurial plugin, or command-line, to view the history of a specific piece of code?

Upvotes: 8

Views: 6312

Answers (4)

Jagat
Jagat

Reputation: 1392

Use hg histgrep --all PATTERN FILENAME (used to be hg grep in the older versions, and that doesn't work anymore)

Upvotes: 0

Robin V.
Robin V.

Reputation: 1542

I don't think there is an option to view a specific part of a file. But to see the differences of the total file over several revisions you can use hg diff:

hg diff -r firstrevisionnumber:otherrevnumber filename

For example, hg diff -r 0:8 screen.css

Or the command hg log screen.css.

Upvotes: 1

Lazy Badger
Lazy Badger

Reputation: 97280

The correct answer is hg grep (Mercurial grep page).

More deep:

hg grep --all "PATTERN" FILENAME

Sample output:

>hg grep --all "textdomain" functions.php
functions.php:2:-:load_theme_textdomain('fiver', get_template_directory() . '/translation');
functions.php:2:+:load_theme_textdomain('fiver', get_template_directory() . '/languages');
functions.php:1:+:load_theme_textdomain('fiver', get_template_directory() . '/translation');

(in order - filename, revision, action, string in this revision)

Upvotes: 21

Bula
Bula

Reputation: 1586

You can use:

hg annotate <file>

to find out in which revision line was changed and then use same command with -r <revision> at the end to go backwards through revisions.

Upvotes: 13

Related Questions