Skip to content

Lesson 4: History and annotate

Select commits with jj's revsets, see what one commit changed, find the change behind each line, and follow a change through its edits.

Time: 20 minutes. Track: developer. Before this: lesson 1.

By the end of this lesson you will be able to:

  • select commits with jj’s revset language;
  • see what one commit changed;
  • find which change wrote each line of a file, and every version a change went through.

A history to read

Start a forge and land three changes to one file, each a step of its own:

$ af-server --dev
...
$ source ~/af-dev/dev/env
$ af workspace add ~/history
Workspace at /home/you/history
Paths: **
main has no landing yet
$ cd ~/history
$ af new -m "Start the changelog"
Working on change toqnotmpsqzlnrxmlmvvokymzrtxxsul at commit 8ab0819e1776efff2c0f33fb284633772fcb004083b89ea6d2e1c7d8c2f72c69
$ printf '# Changelog\n' > CHANGELOG.md
$ af submit
Submitted commit d51da16866e7e5e3b9398853832ea25e01b8b0a69c7a08081ee1c6c295a9ec12, 1 edit in its last snapshot
$ af status
Change toqnotmpsqzlnrxmlmvvokymzrtxxsul (landed) at commit d51da16866e7e5e3b9398853832ea25e01b8b0a69c7a08081ee1c6c295a9ec12
$ af new -m "Note version 1"
Working on change qsvomppyvnkxtvmnvwoskmvkylkoupts at commit f04d2e8dd04db0dce59724ab203e0ea772bd352a3607d06f8b97e8427fe16613
$ printf '# Changelog\n\n- 1: greets you\n' > CHANGELOG.md
$ af submit
Submitted commit 4a745287eada2f8d0055cc09ca300930c0054f4a2ecf36fb96d246c4bc51f7d6, 1 edit in its last snapshot
$ af status
Change qsvomppyvnkxtvmnvwoskmvkylkoupts (landed) at commit 4a745287eada2f8d0055cc09ca300930c0054f4a2ecf36fb96d246c4bc51f7d6
Based on landing 1
$ af new -m "Note version 2"
Working on change rqnpnksroqpnlszsyvquoltxooskuzmr at commit ed62ccf729ec7ba4bc29cee405e5d97ee3cf464c2742cb4720bc2d7cca9786b2
$ printf '# Changelog\n\n- 1: greets you\n- 2: greets you by name\n' > CHANGELOG.md
$ printf 'name = "you"\n' > settings.toml
$ af submit
Submitted commit 24ab4a08d270c3d4ba2d7e955dfbc34dcb493a3f5268263edbfa8726b1e4fd90, 2 edits in its last snapshot
$ af status
Change rqnpnksroqpnlszsyvquoltxooskuzmr (landed) at commit 24ab4a08d270c3d4ba2d7e955dfbc34dcb493a3f5268263edbfa8726b1e4fd90
Based on landing 2

Select commits

af log shows the history your workspace is at. With -r it takes a revset, jj’s language for selecting commits. ::main is main and all that came before it:

$ af log -r '::main'
@  rqnpnksr dev@localhost 2026-11-25T06:17:43Z 24ab4a08
│  Note version 2
○  qsvomppy dev@localhost 2026-11-25T06:17:43Z 4a745287
│  Note version 1
○  toqnotmp dev@localhost 2026-11-25T06:17:43Z d51da168
│  Start the changelog
○  zzzzzzzz  1970-01-01T00:00:00Z 00000000
   (no description set)

files() keeps the commits that touch a path. Only the last change touched settings.toml:

$ af log -r 'files(settings.toml)'
@  rqnpnksr dev@localhost 2026-11-25T06:17:43Z 24ab4a08
│  Note version 2
~

@ is the commit your workspace is at, @- its parent, and @-- the one before:

$ af log -r '@--'
○  toqnotmp dev@localhost 2026-11-25T06:17:43Z d51da168
│  Start the changelog
~

See what a commit changed

af show prints one commit: its ID, author and parents, its description, and each path it changed, marked Added, Modified or Deleted:

$ af show -r @
Commit ID: 24ab4a08d270c3d4ba2d7e955dfbc34dcb493a3f5268263edbfa8726b1e4fd90
Author   : Developer <dev@localhost> (2026-11-25T06:17:43Z)
Parents  : 4a745287eada2f8d0055cc09ca300930c0054f4a2ecf36fb96d246c4bc51f7d6

    Note version 2

M CHANGELOG.md
A settings.toml

Find the change behind each line

af file annotate names, for each line of a file, the change that last wrote it, as jj file annotate does:

$ af file annotate CHANGELOG.md
toqnotmp dev      2026-11-25 06:17:43    1: # Changelog
qsvomppy dev      2026-11-25 06:17:43    2: 
qsvomppy dev      2026-11-25 06:17:43    3: - 1: greets you
rqnpnksr dev      2026-11-25 06:17:43    4: - 2: greets you by name

The heading came from the first change, each version’s line from the change that noted it. A line moved or rewritten later would name the later change.

Follow a change through its edits

A change keeps its ID through every rewrite, and af evolog lists each commit it has been, newest first, with the operation that made it. af status and af evolog first snapshot your files into the change, as jj’s commands do, so an edit followed by one of them is a new commit. Start a change, edit, run af status, edit again, and read the evolution:

$ af new -m "Note version 3"
Working on change snrkrxuvkppqvmrvwnvztslulzvuosuw at commit 1c2c23211f7d4946a48d80b3e03733e800d4889ae5f3bedaaf2e53ae7ef2eb25
$ printf '# Changelog\n\n- 1: greets you\n- 2: greets you by name\n- 3: says goodbye\n' > CHANGELOG.md
$ af status
Change snrkrxuvkppqvmrvwnvztslulzvuosuw (open) at commit 02d14ddc6d8df14ab3c184950dfa2f3ae98c9633456f27bbba6b6348769ba7fc
Based on landing 3
Landing waits for: scan
$ printf '# Changelog\n\n- 1: greets you\n- 2: greets you by name\n- 3: says goodbye too\n' > CHANGELOG.md
$ af evolog
c47c67379d694b9cdc2226dbb397c41335a5c585c74bcc6d803a5bc7ced98250 snrkrxuvkppqvmrvwnvztslulzvuosuw dev@localhost 2026-11-25T06:17:44Z
    Note version 3
    -- operation bbbe09282e3c from 02d14ddc6d8df14ab3c184950dfa2f3ae98c9633456f27bbba6b6348769ba7fc
02d14ddc6d8df14ab3c184950dfa2f3ae98c9633456f27bbba6b6348769ba7fc snrkrxuvkppqvmrvwnvztslulzvuosuw dev@localhost 2026-11-25T06:17:44Z
    Note version 3
    -- operation 20d15a1d9db5 from 1c2c23211f7d4946a48d80b3e03733e800d4889ae5f3bedaaf2e53ae7ef2eb25
1c2c23211f7d4946a48d80b3e03733e800d4889ae5f3bedaaf2e53ae7ef2eb25 snrkrxuvkppqvmrvwnvztslulzvuosuw dev@localhost 2026-11-25T06:17:44Z
    Note version 3
    -- operation 986ec8d1d7cb

Exercises

  1. Select the change that started the changelog by its description. description() matches the whole description, its final newline included, unless you give a kind of pattern: substring: matches any part of it.

    $ af log -r 'description(substring:"Start the")'
    ○  toqnotmp dev@localhost 2026-11-25T06:17:43Z d51da168
    │  Start the changelog
    ~
  2. Show what Note version 1 changed. It is main’s parent, main-:

    $ af show -r 'main-'
    Commit ID: 4a745287eada2f8d0055cc09ca300930c0054f4a2ecf36fb96d246c4bc51f7d6
    Author   : Developer <dev@localhost> (2026-11-25T06:17:43Z)
    Parents  : d51da16866e7e5e3b9398853832ea25e01b8b0a69c7a08081ee1c6c295a9ec12
    
        Note version 1
    
    M CHANGELOG.md

Check your understanding

What is the difference between af log -r '::main' and af log?

af log shows the history your workspace is at, @ and what it was built on. ::main is main and its ancestors, whatever the workspace holds; with an open change, af log shows that change above main too.

af file annotate names a change for each line. Why a change, not a commit?

A change keeps its ID through every rewrite, so the name stays useful after rebases and edits: it is the unit people review and land. The commit is in af show of that change.

Next

Lesson 5: Search finds code on main without a workspace that holds it.

Type to search…

↑↓ navigate↵ selectEsc close