---
title: "Lesson 2: Changes and stacks"
description: "Build a stack of changes, move through it, rewrite a change below you, and land the stack together."
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.forge.workreef.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Lesson 2: Changes and stacks

**Time:** 25 minutes. **Track:** [developer](https://docs.forge.workreef.dev/learn/#developer). **Before this:** [lesson 1](https://docs.forge.workreef.dev/learn/developer/first-landing/).

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

- build a stack, each change on the one below;
- move between the changes of a stack, and fix one while working above it;
- land the stack, and say why its changes land together.

## A stack

Most work comes in steps: a library function first, then the code that uses it. Each step is a change of its own, so each can be read and reviewed on its own, and the second is built on the first. That is a stack.

Start a forge and a workspace:

```console server
$ af-server --dev
...
```

```console check
$ source ~/af-dev/dev/env
$ af workspace add ~/stack
Workspace at /home/you/stack
Paths: **
main has no landing yet
$ cd ~/stack
```

Write the first step:

```console check
$ af new -m "Add a greet function"
Working on change uwwzuxxxzqrtznurrtvkknkskyvnnlwz at commit 0df235ed0188f7b0bae0f9506e1f4f07a1590c21ae7566f5b3337bd650ec5887
$ printf 'def greet(name):\n    return "Hello, " + name\n' > greet.py
```

`af new` while a change is open starts the next change on top of it. Write the second step there:

```console check
$ af new -m "Greet the user"
Working on change mkzlkmznqrzkpkspquwxrmuvmwmvnuoo at commit 427f170af6830e3a8b42eac9125c1e5c7e1b9fb223450b374a76be7888ca3361
$ printf 'from greet import greet\nprint(greet("you"))\n' > main.py
$ af log
@  mkzlkmzn dev@localhost 2026-11-25T06:14:20Z 4b4fa10c
│  Greet the user
○  uwwzuxxx dev@localhost 2026-11-25T06:14:20Z b21d0851
│  Add a greet function
○  zzzzzzzz  1970-01-01T00:00:00Z 00000000
   (no description set)
```

`@` is on the second change, and the first is below it. Each has its own change ID, and each holds only its own step:

```console check
$ af diff
A main.py
--- a/main.py
+++ b/main.py
@@ -0,0 +1,2 @@
+from greet import greet
+print(greet("you"))
```

## Move through the stack

`af prev` takes the workspace to the change below, and `af next` back up. The files on disk follow:

```console check
$ af prev
Working on change uwwzuxxxzqrtznurrtvkknkskyvnnlwz at commit b21d085161ee4f147949c76773a2dbea98bc516e85d8d55fe114412e24d46ec8
$ ls
greet.py
$ af next
Working on change mkzlkmznqrzkpkspquwxrmuvmwmvnuoo at commit 4b4fa10c330ace8676a50eb2d66acdbcbd7e5522bcb8029d17ac94d470a05a73
$ ls
greet.py
main.py
```

## Fix a change below you

Working on the second change, you notice the first should greet more warmly. Make the edit where you are, then move it into the change it belongs in with `af squash`, naming the file:

```console check
$ printf 'def greet(name):\n    return "Hello there, " + name\n' > greet.py
$ af squash greet.py
Rewrote change uwwzuxxxzqrtznurrtvkknkskyvnnlwz at commit f3cf4108b7c32c16a74fd428c84d4e540780282f65e2fc2ea8815082c3103bc8
Rewrote change mkzlkmznqrzkpkspquwxrmuvmwmvnuoo at commit bc033385bf5250271382c662d51b4277b4ae6d283fb362f5acc5ee6c08ef8391
$ af diff
A main.py
--- a/main.py
+++ b/main.py
@@ -0,0 +1,2 @@
+from greet import greet
+print(greet("you"))
```

Both changes were rewritten: the first now holds the warmer greeting, and the second, rebased onto it, holds only `main.py` again. Their change IDs stayed the same; their commits are new. A description is rewritten the same way:

```console check
$ af describe -m "Print a greeting for the user"
Change mkzlkmznqrzkpkspquwxrmuvmwmvnuoo is now at commit 199171e3ca82e592c176707403c833c87951609f4523339d4ebf1cb0f4026bdc
```

## Land the stack

Submit from the top. The changes of a stack land together, in order, or not at all: the second needs the first, and main never holds the second without it.

```console check
$ af submit
Submitted commit 199171e3ca82e592c176707403c833c87951609f4523339d4ebf1cb0f4026bdc, 0 edits in its last snapshot
```

```console eventually
$ af status
Change mkzlkmznqrzkpkspquwxrmuvmwmvnuoo (landed) at commit 199171e3ca82e592c176707403c833c87951609f4523339d4ebf1cb0f4026bdc
```

Both changes are on main now, in order: the greet function, then the code that uses it.

## Exercises

1. Your stack has landed, so a new change starts on main again. Build a new stack of two: a readme, then a changelog on top of it. Then go down to the readme: the changelog is not on disk there.

   ```console check
   $ af new -m "Add a readme"
   Working on change rwyszrynpyxzrkmtoquwsxloykunvqxx at commit 05b8e24a72b76d0fb29325f3587045a7494c3d1d103947953a83ee13c7a4f8af
   $ printf 'Greets you\n' > README
   $ af new -m "Add a changelog"
   Working on change rtwwtxzvwkllyqylnolztqkoqmtrvvsn at commit fd000f8c30907d91b2253fbb289e5d5726031de17676968187d3cffdaa76ad66
   $ printf 'Version 1: greets you\n' > CHANGELOG
   $ af prev
   Working on change rwyszrynpyxzrkmtoquwsxloykunvqxx at commit 06387416c5b47477fc5a6cff17ee55069df006546cfa912eb0e32af6d16da88e
   $ ls
   README
   greet.py
   main.py
   ```

2. Go back up with `af next`, and land the stack from the top. The readme lands with it:

   ```console check
   $ af next
   Working on change rtwwtxzvwkllyqylnolztqkoqmtrvvsn at commit 2b78c10611a4ac204d43c4f93bea6f0d7b3df4bb834265655a8862af71a0da5f
   $ af submit
   Submitted commit 2b78c10611a4ac204d43c4f93bea6f0d7b3df4bb834265655a8862af71a0da5f, 0 edits in its last snapshot
   ```

   ```console eventually
   $ af status
   Change rtwwtxzvwkllyqylnolztqkoqmtrvvsn (landed) at commit 2b78c10611a4ac204d43c4f93bea6f0d7b3df4bb834265655a8862af71a0da5f
   Based on landing 2
   ```

3. `af prev` on the bottom change of a stack has nowhere to go. Try it on the readme's change once both have landed and you have started a new change: what does it say?

   <details>
   <summary>Answer</summary>

   `Error: no open change is below this one`: a new change after a landing starts on main, with no open change below it.

   </details>

## Check your understanding

<details>

<summary>

What did `af squash greet.py` change, and what stayed the same?

</summary>

It moved your edit of `greet.py` from the workspace's change into the change below it, so both changes got new commits, the one above rebased onto the new one below. Their change IDs and descriptions stayed the same.

</details>

<details>
<summary>Why does a stack land together?</summary>

Each change in it is built on the one below. Landing the top alone would put on main a change whose base main does not hold, so the forge lands the stack in order, or none of it.

</details>

## Next

[Lesson 3: Rebasing and conflicts](https://docs.forge.workreef.dev/learn/developer/rebasing-and-conflicts/) follows main as other people land, and resolves a conflict.

Source: https://docs.forge.workreef.dev/learn/developer/changes-and-stacks/index.mdx
