Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 327
esther h Avatar asked Nov 25 '12 08:11

esther h


3 Answers

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)

like image 75
Lazy Badger Avatar answered Nov 05 '22 22:11

Lazy Badger


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.

like image 13
Bula Avatar answered Nov 05 '22 23:11

Bula


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.

like image 1
Robin V. Avatar answered Nov 05 '22 22:11

Robin V.