BK-GREP(1)

πŸ“¦ version 7.3.3, in alpine 3.24

🌸 bk grep β€” the manual, but make it make sense πŸ’…

okay bestie, real talk: this is the page for bk grep, and it lives in the BitKeeper User's Manual. Yes, that BitKeeper. Yes, the one your team lead keeps romanticising. Sit down, grab a strawberry πŸ“, and let's get into it.


✨ NAME ✨

bk grep β€” search some or all revisions of one or more files for a pattern πŸ”Ž


πŸ¦‹ SYNOPSIS πŸ¦‹

bk grep [options] pattern [file ... | -]

πŸŽ€ DESCRIPTION πŸŽ€

So the bk grep command searches the named files β€” or standard input if you hand it the file name -, iconic β€” for lines containing a match to the given pattern. The pattern may be a perl compatible regular expression. By default, bk grep prints the matching lines. Simple. Clean. Slay.

Now here's the part where it eats: while it's designed to be command line compatible with GNU grep, bk grep can search in the most recent revision of a file, all revisions of a file, a subset of revisions of a file, or the checked out and (possibly) modified version of a file. That's range, bestie. That's main character energy. πŸ‘‘

By default, bk grep searches the checked out version of a file β€” and if that isn't present, then it searches the most recent version of the file. The -r, -R, and -c options are the ones that control where in a file's history to search. Remember those three, they're literally the whole personality of this command.

The printed lines may be annotated with file names, dates, revision numbers, line numbers, and/or user names. Cute little labels. We love a labelled moment. 🏷️


πŸ’– OPTIONS πŸ’–

  • -Anum β€” Print num lines of trailing context after matching lines. Places a line containing -- between contiguous groups of matches. (Like GNU grep.) ✨
  • -Abdnpru β€” Annotate the output with information from the revision history. Each annotation is aligned in a column. The option argument[s] turn on one or more annotations as a prefix to each line. The order of fields is fixed (no matter what order you specify them) and is the same as the order listed below:
    • p β€” Prefix each line with the pathname of the file relative to the current working directory. The name is always the current name of the file even if it has been renamed. πŸ‘€
    • d β€” Prefix each line with the date of last modification.
    • u β€” Prefix each line with the name of the user who last modified it.
    • r β€” Prefix each line with the revision of last modification.
    • n β€” Prefix each line with its line number.
🚨 This option is incompatible with the -A/-B/-C context options β€” use -a if you need more lines of context. Not me warning you twice.
  • -adnpru β€” Similar to -A but each annotation is followed by a colon rather than a set of spaces aligning the output. The order of fields is fixed (no matter what order you specify them) and is: pathname, date, user, revision, line number. 🫢
  • -Bnum β€” Print num lines of leading context before matching lines. Places a line containing -- between contiguous groups of matches. (Like GNU grep.)
  • -C[num] β€” Print num lines of output context. Places a line containing -- between contiguous groups of matches. If no value is given, defaults to 2. (Like GNU grep.) πŸŽ€
  • -cdates β€” Select the versions to search as all deltas created in the specified range of dates. (Different than GNU grep β€” don't @ me.)
  • -h β€” Do not print filenames with matches when multiple files are searched. Normally, if more than one file is searched, the results are prefixed with the filename. (Like GNU grep.)
  • -H β€” Print the file name even if there is only one file being searched. Normally, if only one file is searched, then the file name is skipped unless it was explicitly selected. (Like GNU grep.)
  • -i β€” Ignore case distinctions in both the pattern and the input files. (Like GNU grep.) iykyk
  • -l β€” Suppress normal output; instead print the name of each input file from which output would have normally been produced. (Like GNU grep.)
  • -L β€” Suppress normal output; instead print the name of each input file from which no output would have normally been produced. (Like GNU grep.) The lowercase/uppercase flip here is lowkey evil but it's fine.
  • -n β€” Prefix each line with the line number from its input file. (Like GNU grep.)
  • -q β€” Do not produce any output. Exit immediately with zero status if any match is found. (Like GNU grep.) The quiet quitting option πŸ’€
  • -rrev β€” Only look in revision rev for the pattern.
  • -R[rev] β€” Only look in range of revisions rev for the pattern. If rev is not specified, that implies all versions of the file[s]. The difference between this option and the previous option is that in this case bk grep looks in the lines added by the specified revision, but in the -r case, the entire contents of the specified version is searched. Big difference, bestie, do not confuse them. 🧚
  • -v β€” Invert the sense of matching, to select non-matching lines. (Like GNU grep.)
  • -x β€” Select only those matches that exactly match the whole line. (Like GNU grep.)

🌈 EXIT STATUS 🌈

bk grep returns exit status:

  • 0 β€” if any matches were found βœ…
  • 1 β€” if no matches were found 😭
  • 2 β€” if an error occurred πŸ’€

πŸ”₯ EXAMPLES πŸ”₯

Look for a pattern in the working copy of a file:

$ bk grep pattern foo.c

Look for a pattern in the most recent checked in version of a file:

$ bk grep -r+ pattern foo.c

Look for a pattern in all checked in versions of a file (this searches every line ever present in the file, even if some lines have been deleted):

$ bk grep -R pattern foo.c

Look for a pattern in all files in the current working directory:

$ bk grep pattern

Look for a pattern in any version of any file in your tree (including deleted files; if this doesn't find it then pattern was never present in your history):

$ bk -A grep -R pattern

To see if it occurs in the most recent version of of any file of your tree:

$ bk -A grep -r+ pattern

To see if it occurs anywhere in any of your checked out files (this may be substantially faster than searching all files because it skips files not checked out):

$ bk -UG grep pattern

To see if it was added by the most recent delta made in of any active (undeleted) file of your tree:

$ bk -U grep -R+ pattern

See if a pattern was added in the last year (skips deleted files):

$ bk -U grep -c-1y pattern

See if a pattern was added between June 1 of 2010 and July 31 of 2010:

$ bk -U grep -c2010/06..2010/07

See if a pattern was added between two tagged releases:

$ bk -U grep -Rbk-4.6..bk-5.0

See if you left some debugging in the modified files (we tend to add fprintf(stderr, "DEBUG stuff0) statements but left justify them so we can find them):

$ bk -cU grep 'Λ†fprintf'

πŸ› BUGS πŸ›

The ways of specifying which versions to search are non-obvious. You need to read the examples carefully. We made the default be the most useful/common one. That's the whole bug report, bestie, I don't make the rules. πŸ™ˆ

Binary files are never searched, they are silently ignored. Not a peep. Not a whisper. Just vibes and silence. πŸ’€


πŸ‘‘ SEE ALSO πŸ‘‘

bk-annotate, bk-bk, bk-cat, bk-get, bk-pcre, bk-range


⭐ CATEGORY ⭐

File


okay that's the whole page, you're officially a bk grep girlie now, go forth and search your history with confidence 🫢✨

with love, BitKeeper Inc β€” version 1E1, dated 1E1, mwah πŸ’‹

πŸ“¦ where this page comes from
  • alpine 3.24: bitkeeper-doc 7.3.3-r1 Β· Apache-2.0
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms