UFC Insider
UFC Insider

Reputation: 838

mercurial - first revision a string appeared

Say the string "abc123" first appeared in revision 12, and the current revision is 200. How can I know that the string "abc123" first appeared in revision 12? Plus, how do I get verision 12's hash?

Upvotes: 0

Views: 82

Answers (1)

Reimer Behrends
Reimer Behrends

Reputation: 8720

You should be able to use

hg grep abc123 -r 0:tip

to search revisions in order for the first revision that the string abc123 appears in. Keep in mind that this can be a very slow process for a large repository with a long history, as each revision will have to be checked individually.

To speed up the process for such a repository, you can use hg bisect. E.g.:

hg bisect -r            # reset bisect if needed
hg bisect -g 0
hg bisect -b tip
hg bisect -c '! hg grep -r . abc123'

Note that marking revisions that contain the string as "bad" and those that don't contain it as "good" seems counterintuitive, because bisect is normally used to hunt for the first revision that contains a bug. Thus the "bad" revisions are the ones that contain the string.

Note also that bisect may not work if there are revision ranges that do not contain the string you are looking for.

Finally, the ! operator to negate a shell exit code may not be supported by some shells. In those cases, use

hg bisect -c 'if hg grep -r . abc123; then false; else true; fi'

instead.

To get the hash of (say) revision 12, use:

hg id -i -r 12

or:

hg id --debug -i -r 12

The latter version will print the full hash, the former will give you the abbreviated hash.

Upvotes: 2

Related Questions