Back to AI Q&A
How do I revert codex bad code? Keep diff first and then undo

How do I revert codex bad code? Keep diff first and then undo

AI Q&A Admin 1744 views

When Codex changes bad code, the most taboo thing is to manually delete it everywhere. Keep the diff first to confirm which files were changed by it, and then roll back according to the Git granularity. This can not only restore the project, but also leave clues to the problem and avoid repeating the pit next time.

First thing: see what has been changed first

Execute 'git status' in the project root directory and see 'git diff'. If there are many changes, do not remove them directly, but first classify them by file: business code, configuration file, lock file, generate file, and test file. Many failures actually come from only one or two configuration or import paths, and you don't have to lose all the results.

If you haven't committed it yet, it's recommended to save a temporary patch: git diff > codex-bad-change.patch. This document is not for launch, but for future comparison.

How to fall back more stable

If only a file is broken, only restore that file, don't empty the entire repository. You can use the Source Control panel in the editor to discard file-by-file, or you can use Git's file-level recovery.

If the Codex changes span many files, let it explain why each file was changed. Documents that cannot be explained are removed first; Explain clearly but implement a bug in the file and then fix it partially.

How to avoid changing too much next time

Let Codex only handle one goal at a time: write tests first, then change implementations, and finally run validation. Don't let it refactor, fix bugs, change the UI, and optimize performance in a single message. The more confused the task, the harder it is to undo the diff.

You can also specify before you start: "Make up to 3 changes at a time, list the plan before modification, and list the actual changes and validation commands after completion." "This significantly reduces the probability of losing control.

What to do without Git

For projects without Git, copy and back up the current directory before letting the AI change it. A better approach is to initialize Git immediately and commit the current runnable state once. AI programming tools are great for quick changes, but only if you have a rollback point.

The conclusion is simple: Codex is not terrible to change code, but the scary thing is that there is no diff, no commit, no boundary. As long as you leave evidence first and then revert according to the document, most problems can be recovered quickly.

Recommended Tools

More