-
-
Notifications
You must be signed in to change notification settings - Fork 90
Command: git query
Available since v0.4.0.
git query
is used to execute queries about the commit graph. You can use the results interactively or as part of your scripts. Since git query
accepts revsets, you can issue more complicated queries than are possible with e.g. git log
.
git query
accepts a revset expression and prints out a list of commit hashes corresponding to the commits that matched that expression. The output is topologically-sorted, i.e. ancestor commits will appear before descendant commits in the list.
By using a revset expression, you can query the commit graph for various patterns. For example, to find all commits in the current stack which touched eval.rs
, you could run this:
$ git query 'stack() & paths.changed(eval.rs)'
410b9f1 feat(revset): rename `nth*` revset functions
943a55e feat(revset): add `{author,committer}.date` revset functions
41adb5e feat(revset): add `{author,committer}.{name,email}()` revset functions
f6a2983 feat(revset): create `paths.changed()` revset function
72deb33 feat(revset): create `message()` revset function
527aa53 feat(revset): create `all()`, `none()` revset functions
901101d feat(revset): update `stack()` revset function to accept zero or one arguments
29a6f9b feat(revset): support builtins with multiple arities
2c127cb refactor(revset): extract `builtins` module
By default, the output of git query
is human-readable. For use in scripts or other automation, you can pass the -r
/--raw
flag to get a list of commit hashes instead, one per line:
$ git query 'stack() & paths.changed(eval.rs)' -r
410b9f127be48eada5b625c2e5f1d277c52abb82
943a55e06cf10cef8c114c20954b312253ea6632
41adb5e95524a9cf3ee48b464149787229131f7b
f6a29835867ca5588e16ce0f22590399124da332
72deb33870c7ee889a261f7af439e912ba9a9d63
527aa53bdedb93a8ce3e72bf0c72ea7c26dcdf0e
901101dd65c488d5c3ec562c95f202114b24eb4c
29a6f9bc6f2dc68b8d93b62f6079e9c656581ea3
2c127cbb99b85bcd7ab70ab0d5c748251b8b3166
The output is guaranteed to be topologically sorted, i.e. every commit will appear in the list before any of its descendants.
By default, git query
prints a list of commits. If you want to get the branches attached to those commits, you can add the --branches
option. For example, to get the list of all branches pointing to draft commits, you could run:
$ git query --branches 'draft() & branches()'
- Search the Wiki 🔎
- User guide
- Welcome
- Installation
- Tutorial
- Command overview
- General:
- Navigation:
- Committing:
- Rebasing:
- Verification:
- Collaboration:
- Workflows
- Advanced topics
- Reference
- Developer guide
- Onboarding offer
- Development
- Reference