BK-GREP(1)
πΈ 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β Printnumlines 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/-Ccontext options β use-aif you need more lines of context. Not me warning you twice.
-adnpruβ Similar to-Abut 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β Printnumlines of leading context before matching lines. Places a line containing--between contiguous groups of matches. (Like GNU grep.)-C[num]β Printnumlines of output context. Places a line containing--between contiguous groups of matches. If no value is given, defaults to2. (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 revisionrevfor the pattern.-R[rev]β Only look in range of revisionsrevfor the pattern. Ifrevis not specified, that implies all versions of the file[s]. The difference between this option and the previous option is that in this casebk greplooks in the lines added by the specified revision, but in the-rcase, 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
- Copyright (c) 1998-2015 BitKeeper Inc
- Copyright (C) 1989, 1990, 1991, 1992, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms