> ## Documentation Index
> Fetch the complete documentation index at: https://codegeninc-codegen-bot-sdk-docs-2-0.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Commit and Reset

Codegen requires you to explicitly commit changes by calling [codebase.commit()](/api-reference/core/Codebase#commit).

<Tip>
  Keeping everything in memory enables fast, large-scale writes. See the [How it
  Works](/introduction/how-it-works) guide to learn more.
</Tip>

You can manage your codebase's state with two core APIs:

* [Codebase.commit()](/api-reference/core/Codebase#commit) - Commit changes to disk
* [Codebase.reset()](/api-reference/core/Codebase#reset) - Reset the `codebase` and filesystem to its initial state

## Committing Changes

When you make changes to your codebase through Codegen's APIs, they aren't immediately written to disk. You need to explicitly commit them with [codebase.commit()](/api-reference/core/Codebase#commit):

```python
from codegen import Codebase

codebase = Codebase("./")

# Make some changes
file = codebase.get_file("src/app.py")
file.before("# 🌈 hello, world!")

# Changes aren't on disk yet
codebase.commit()  # Now they are!
```

This transaction-like behavior helps ensure your changes are atomic and consistent.

## Resetting State

The [codebase.reset()](/api-reference/core/Codebase#reset) method allows you to revert the codebase to its initial state:

```python
# Make some changes
codebase.get_file("src/app.py").remove()
codebase.create_file("src/new_file.py", "x = 1")

# Check the changes
assert codebase.get_file("src/app.py", optional=True) is None
assert codebase.get_file("src/new_file.py") is not None

# Reset everything
codebase.reset()

# Changes are reverted
assert codebase.get_file("src/app.py") is not None
assert codebase.get_file("src/new_file.py", optional=True) is None
```

<Note>
  `reset()` reverts both the in-memory state and any uncommitted filesystem
  changes. However, it preserves your codemod implementation in `.codegen/`.
</Note>
