Sessions, Branches & Rollback¶
Sessions track the current image and its history as you run commands. Every
non-disposable contree run produces a new image, and the session records
the chain. Sessions also support branching and rollback for
experimentation.
Session key¶
Every session is identified by a session key – an arbitrary string. The CLI computes one automatically so that each terminal window gets its own session without any extra setup.
The auto-generated key is a deterministic UUID5 derived from three values:
Component |
Source |
Purpose |
|---|---|---|
|
Active config profile name |
Isolates sessions per profile |
|
Parent process ID ( |
The shell that launched the CLI |
|
TTY device of stdin ( |
Distinguishes terminal windows |
In practice this means:
Open a new terminal tab – new
ppid+tty– new session.Run
contreecommands in the same terminal – sameppid+tty– same session (resumes where you left off).Switch profiles – different
profile– new session.
Viewing session state¶
contree session # show current session info
contree session list # list all sessions
contree session show # show full history DAG
contree session
contree session list
contree session show
Branching¶
Create a branch to experiment without affecting the main line:
contree session branch experiment
contree session checkout experiment
contree run apt-get install -y curl
contree session branch experiment
contree session checkout experiment
apt-get install -y curl
Not happy? Switch back:
contree session checkout main
contree session checkout main
Branches share history entries – creating a branch just creates a new pointer at the current position.
Create a branch from another branch:
contree session branch hotfix --from main
contree session branch hotfix --from main
List branches (* marks the active one):
contree session branch
contree session branch
Rollback¶
Undo the last N operations on the current branch:
contree session rollback # undo last 1
contree session rollback 3 # undo last 3
contree session rollback
contree session rollback 3
This moves the branch pointer backwards in the history chain. The history entries still exist and can be recovered by creating a branch at a specific point.
Starting a fresh session¶
Because the auto-generated key is deterministic, the same terminal always
resumes the same session. Use --new (-N) to start a fresh session:
# bash / zsh
eval $(contree use -N tag:python:3.11-slim)
# fish
eval (contree use -N tag:python:3.11-slim)
Without eval, the new session is not active until you export the
printed variable into your shell. You can also copy-paste the export
(or set -gx) line that contree use prints.
contree use -N tag:python:3.11-slim
Inside the interactive shell, no eval is needed – the new session is
activated automatically.
You can also set CONTREE_SESSION to any string:
export CONTREE_SESSION=tutorial
contree use tag:python:3.11-slim
Unset it to go back to the automatic key:
unset CONTREE_SESSION
Storage¶
Session data is stored in a SQLite database at
~/.local/lib/contree-cli/sessions.db. Override with
CONTREE_SESSION_DB:
export CONTREE_SESSION_DB=/tmp/my-sessions.db
You can experiment freely with branches. Next: Working with Files.