HG(GREP)

πŸ’– NAME πŸ’–

hg grep β€” bestie, it's literally search for a pattern in specified files. That's it. That's the whole gig. ✨


🌸 SYNOPSIS 🌸

hg grep [--diff] [OPTION]... PATTERN [FILE]...

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so picture this: you wanna hunt down a regular expression across the files you picked, and you can do it in your working directory or in your revision history β€” and yes, for the entire repository. πŸ‘‘

By default, grep searches the repo files sitting in your working directory and just prints the files where it found a match. Want historical revisions instead of the working directory? That's what the --rev flag is for, no cap.

Wanna search historical revision differences instead β€” the ones where the match status actually changed? Use the --diff flag. The tea: a - means a match that becomes a non-match, and a + means a non-match that becomes a match. It's giving glow-up vs. glow-down. πŸ’€

PATTERN can be any Python (roughly Perl-compatible) regular expression. Slay.

If you don't specify any FILEs and you didn't supply the --rev flag, then every file in the working directory gets searched. And if you are using --rev and you're specifying FILEs, use the --follow argument so it also follows those FILEs across renames and copies. That part matters, don't skip it. 🫢

✨ Template ✨

These keywords are supported in addition to the common template keywords and functions. Also peek at hg help templates, bestie.

  • change β€” String. Character denoting insertion + or removal -. Only available if --diff is specified.
  • lineno β€” Integer. Line number of the match.
  • path β€” String. Repository-absolute path of the file.
  • texts β€” List of text chunks.

And each entry of {texts} provides these sub-keywords, iykyk:

  • matched β€” Boolean. True if the chunk matches the specified pattern.
  • text β€” String. Chunk content.

See hg help templates.operators for the list expansion syntax.

Returns 0 if a match is found, 1 otherwise. Periodt. πŸ’…


πŸŽ€ OPTIONS πŸŽ€

  • -0, --print0 β€” end fields with NUL. (yes, the null byte, iconic)
  • --all β€” an alias to --diff (DEPRECATED). ⚠️ It's giving legacy, bestie.
  • --diff β€” search revision differences for when the pattern was added or removed
  • -a, --text β€” treat all files as text
  • -f, --follow β€” follow changeset history, or file history across copies and renames
  • -i, --ignore-case β€” ignore case when matching
  • -l, --files-with-matches β€” print only filenames and revisions that match
  • -n, --line-number β€” print matching line numbers
  • -r,--rev <REV[+]> β€” search files changed within revision range
  • --all-files β€” include all files in the changeset while grepping (DEPRECATED). ⚠️ Also legacy, also still real.
  • -u, --user β€” list the author (long with -v)
  • -d, --date β€” list the date (short with -q)
  • -T,--template <TEMPLATE> β€” display with template
  • -I,--include <PATTERN[+]> β€” include names matching the given patterns
  • -X,--exclude <PATTERN[+]> β€” exclude names matching the given patterns
[+] marked option can be specified multiple times. So go off, stack 'em up. πŸ’–

Okay so that's the whole hg grep manual β€” every flag, every keyword, every deprecated lil relic, all accounted for, fr fr. It's from the HG(GREP) page, and yeah the footer says the same thing: HG(GREP). Go search something and make it everyone's problem. πŸ§šβ€β™€οΈπŸ’œ