4

I want to search for a filename across all my commits/branches and find out which commits/branches contain that filename. I don't know which subdirectory/subdirectories of the repo the file would be in.

I've tried hg grep <filename>, but that only seems to show files containing "filename".

I've also looked at Mercurial - determine where file was removed?, but that really help me if a file was created on a different branch. The person asking that question suggested hg log myfile -v, which seems like it could work, but doesn't. I know that somewhere in my repo the file exists because I get something back when I do find .hg | grep <filename>, but that doesn't tell me (at least not clearly) which commits/branches.

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
Benjamin Berman
  • 521
  • 4
  • 15

2 Answers2

4
  1. You have to read hg help patterns and maybe hg help filesets in order to write correct pattern for the file (most probably you'll be happy with just pattern)
  2. If file exist now in working directory (i.e. was added and not removed later), you'll find it with hg file <PATTERN> and will determine full path by output, see above (pattern used)

>hg file **/test-extra.t tests\test-extra.t

and call hg log with full filename

  1. In any case (hg file returned 0 for removed file or file still in WD) you can call hg log <FILESET> and get history too. Log for existing will be too long, will show deleted unique filename sample

>hg log set:**/dulwich/tests/__init__.py -Tcompact 223 0b6c08800d16 2009-07-23 08:48 +0100 a delete the dulwich fork we have
2 c43c02cc803a 2009-04-22 16:59 -0700 schacon added dulwich library and got the script to call it for clone

  1. If your set will be too wide and (may) include files with the same name in different folders, you have to verify filenames by calling log with more details about files, f.e. with -Tstatus
Lazy Badger
  • 94,711
  • 9
  • 78
  • 110
2
hg log 'glob:**/<filename>` -Tstatus

seems to do the job. It doesn't give me the commits containing <filename>, but it does give commits (and their branches) involving filename.

Credit to Lazy Badger's answer for pointing me to this.

Benjamin Berman
  • 521
  • 4
  • 15