Search code examples
eclipsemercurial

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?


Solution

  • 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)