HG: find where a deleted line was removed
Asked Answered
V

2

31

I am looking for the mercurial equivalent of the solution to this question:

How do I "git blame" a deleted line?

In short, I am looking at a mercurial commit where a line was added, and in the current revision this line is no longer present, and I want to find when and why it was removed.

Valina answered 3/5, 2012 at 16:33 Comment(3)
Not quite a duplicate, but see this question.Wharfinger
wonderful, this helped me get from hg show 9876:tip path/to/file | grep --all "pattern" -U20 to hg grep -r 9876:tip "pattern" path/to/file, which was just what I needed. If you give that as an answer I'll accept it. Originally I tried it without --all, thinking that it was a substitute for the -r flag, but found that it only lists the first revision unless --all is specified.Valina
Thanks for the offer, Brian, but I only pointed you to an existing answer which solved it. Write up a short answer and give krtek an upvote :)Wharfinger
V
35

hg histgrep will let you search a change log for a pattern, such as a deleted string. If you are looking for more than just the first occurrence, be sure to include the --all flag. For me it looked something like this:

hg histgrep --all -r 9876:tip "pattern" path/to/file

Thanks to Anton for the helpful comments and krtek for his related answer.

Valina answered 7/5, 2012 at 16:44 Comment(4)
hg grep has been renamed to hg histgrep in the meantime. besides that the answer is still valid.Fusibility
@stigli: It has? I can't find any reference to that, even in latest Mercurial (3.8.3+).Flour
@stigi: hg histgrep doesn't appear to exist in hg 4.5.3. hg grep still works.Hibbert
@Fusibility Confirming hg histgrep is present in my version of Mercurial 4.4.2. Running hg grep -h shows "For the old 'hg grep', which searches through history, see 'histgrep'."Abjuration
D
1

hg log -p fileName > fileName.log

Then open the fileName.log file

In there you will find commit the details of each commit along with the diff of that commit. The details of the commit includes the username.

Darton answered 3/1, 2020 at 13:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.