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():
Copy
Ask AI
from codegen import Codebasecodebase = Codebase("./")# Make some changesfile = codebase.get_file("src/app.py")file.before("# 🌈 hello, world!")# Changes aren't on disk yetcodebase.commit() # Now they are!
This transaction-like behavior helps ensure your changes are atomic and consistent.
The codebase.reset() method allows you to revert the codebase to its initial state:
Copy
Ask AI
# Make some changescodebase.get_file("src/app.py").remove()codebase.create_file("src/new_file.py", "x = 1")# Check the changesassert codebase.get_file("src/app.py", optional=True) is Noneassert codebase.get_file("src/new_file.py") is not None# Reset everythingcodebase.reset()# Changes are revertedassert codebase.get_file("src/app.py") is not Noneassert codebase.get_file("src/new_file.py", optional=True) is None
reset() reverts both the in-memory state and any uncommitted filesystem
changes. However, it preserves your codemod implementation in .codegen/.