See and undo a change to the report's code
Put the report's contract under version control, let an AI quietly loosen a rule, see exactly what changed, and put it back.
2 parts · 3 and 11 min · part 2 on a computer
Free course. Your Maestro, an AI, .
On the previous page, changing a single order amount in September's data changed the report's fingerprint while leaving no clue which row had been touched. The same hazard applies to the Glossary word itself. When you ask an AI assistant to tidy up contract.py or report.py, it can rewrite a condition while changing a variable name or formatting a loop. Because the edited file still runs from start to finish without raising an error, everything looks fine until a bad row passes straight into finance's totals.
Version control protects reproducibility by keeping your code anchored to a known-good state through three moves:
- Commit an approved version. Once finance confirms that the report and its rules behave as expected, you record a snapshot of the files along with a message stating why that version matters, such as
"Contract as finance approved it". Keeping a separate folder namedproject_backup_oldonly leaves you guessing which file changed and when; a commit ties the exact file contents to an ordered log entry right inside your project. Committing also stays local on your computer, so recording a version never publishes or sends your files anywhere else. - See what changed (
diff). Whenever you or an AI edits a file, you compare the working file in your folder against the last committed snapshot. A unified diff ignores every unchanged part of the file and prints only the lines that were removed (marked with-) and the lines that replaced them (marked with+), framed by a few neighboring lines so you can see where the edit sits. - Restore the committed version. When the diff reveals an unwanted edit, you copy the committed snapshot back over the working file. Diffing again returns an empty result, confirming that the code on disk matches the approved version byte for byte.
How version_demo.py shows the three moves
Because git is not installed in this course sandbox, version_demo.py implements those same three moves in plain Glossary word inside a temporary working folder:
commit(message)creates a numbered snapshot directory insideversions/, copies the currentcontract.pyintoversions/1/contract.py, and appends"1 Contract as finance approved it"tolog.- Right after that commit, the script simulates an AI edit that rewrites
if amount < 0:asif amount < -1000:in the working copy ofcontract.py. The code still runs cleanly, yet any negative order amount between-1000and0would now slip past the contract without a warning. diff()runsdifflib.unified_diffbetweencommitted/contract.pyandworking/contract.py, printing the exact line where the threshold moved.
If the - and + lines in the unified diff output look unfamiliar, ask your Maestro to walk through them with you.
Try it
Run version_demo.py first to see the unified diff of the AI's edit to contract.py. Then complete the bottom of version_demo.py to copy version 1 from versions/1/contract.py back over path, print the difference again, and print log.
A good place to stop. Up next: the workbench · 11 min · on a computer
When your restore step works, the script prints the unified diff showing - if amount < 0: and + if amount < -1000:, followed by Difference after restore: '' and Log: ['1 Contract as finance approved it']. Copy the committed file back with shutil.copy(os.path.join(versions, "1", "contract.py"), path) and print repr(diff()) so the empty string '' is visible. If your difference after restore is still not empty, paste your last three lines to your Maestro.
The same moves with git on your own machine
On your own computer, you run git in a Glossary word inside the project folder instead of writing a Python helper. Each function in version_demo.py corresponds to a standard git command:
git initstarts version tracking in the current folder, andgit add contract.py report.pyfollowed bygit commit -m "Contract as finance approved it"records the approved snapshot.git diffprints the exact line-by-line unified diff between the committed snapshot and your working files.git restore contract.pyoverwrites the workingcontract.pywith the last committed snapshot, undoing the AI's edit.git log --onelineprints the one-line history of commits in the folder.
git initgit add contract.py report.pygit commit -m "Contract as finance approved it"git diffgit restore contract.pygit log --oneline