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

末鹿安然 提交于 2019-12-23 09:36:35

问题


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?


回答1:


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)




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/13549555/mercurial-how-to-see-the-history-for-a-specific-line-of-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!