gitmercurialmercurial-revsets

What is the git equivalent of Mercurial revsets?


Mercurial has a domain-specific language called revsets that allows users to specify sets of revisions.

For example, you might want to list patches that haven't yet been merged into the branch default:

hg log -r "all() - ancestors('default')"

As a more complex example, the link above gives the example of listing changesets between the revision tagged 1.3 and the revision tagged 1.5 which mention "bug" and affect a file in the directory hgext:

hg log -r "1.3::1.5 and keyword(bug) and file('hgext/*')"

The revset language is quite rich, allowing selection of changesets based on dates, username, commit message, whether the commit exists at a particular remote location, and so on.

Does git have an equivalent mechanism for querying changesets, either in the core program or available as an extension?


Solution

  • The git-branchless suite of tools now includes a revset-like language under the command git branchless query.

    Once installed and initialised on the current repository, the examples in the previous question (from eight years ago!) could be queried as follows:

    # List patches not yet been merged into the branch default:
    git branchless query "all() - ancestors('default')"
    
    # List patches between the revision tagged 1.3 and the revision tagged
    # 1.5 which which mention "bug" and affect a file in the directory hgext
    git branchless query "1.3::1.5 and message('bug') and paths.changed('glob:hgext/*')"
    

    These are remarkably similar to their HG equivalents.