# Undo and history

> Every GUIJam change is journaled with the exact previous bytes. Undo restores your files exactly, refuses to overwrite your own edits and survives crashes.

GUIJam never writes a file it can't put back. Every applied change is recorded in a journal in your project, with the exact bytes each file had before.

## Undo a change

After every **Apply** or **Use**, a toast offers **Undo** for 10 seconds. Undo:

- Restores the exact previous bytes of every file the change touched.
- Deletes the files the change created, such as new components from a sketch.
- Leaves libraries the change installed in place. Remove those yourself if you don't want them.

When it's done, GUIJam shows "Change undone."

## Your edits come first

GUIJam checks each file before writing to it:

- **Before applying a change**, it makes sure the file still matches what the change was based on. If you edited the file in the meantime, the change is refused with "Your edits to `<file>` conflict with this change. Review them, then preview again."
- **Before undoing**, it makes sure the file still matches what GUIJam wrote. If you changed it since, undo is refused rather than overwriting your work.

## The journal

The journal lives in `.guijam/journal/` in your project, one file per month, with the previous contents of each file stored by content hash. See [The .guijam directory](https://guijam.francistinao.com/docs/reference/guijam-directory).

Each change is journaled before it touches your files. GUIJam saves the previous contents, records that the change began, writes every file or none of them, then records that it finished.

## Crash recovery

If the daemon stops in the middle of a change, it checks the journal the next time it starts:

| Files found             | What GUIJam does             |
| ----------------------- | ---------------------------- |
| All at the new contents | Marks the change as done     |
| All at the old contents | Marks it as not applied      |
| Some old, some new      | Rolls the changed files back |

So a change is either fully applied or not applied at all.

## Keep it out of git

The journal is local history, not part of your project. `init` adds `.guijam/` to your `.gitignore`.
