1.3 Minimal Git and diff safety
Explanation
Before asking an AI agent to edit files, make sure you have a way to inspect and undo changes.
If you downloaded the ZIP file and have not learned Git yet, keep the first edits small. Before a large edit, make a copy of the file or folder you are about to change. This is simple, but it is not as powerful as Git.
If you cloned the repository, or if the folder is already a Git repository, use these commands as the minimum safety check:
git status
git diffgit status shows which files changed. git diff shows the actual text changes.
If an edit is clearly wrong and you want to discard local changes in one file, use:
git restore path/to/fileBe careful: git restore discards local changes in that file. Do not use it on work you still need.
A commit is a checkpoint. After you understand a useful change and the checks pass, save it:
git add path/to/file
git commit -m "short description"Git is explained more fully later in Git basics for scientific workflow. For now, remember the minimum rule: after an AI agent edits files, inspect the diff before accepting the change.
Things to look up
- Git status
- Git diff
- Git init
- Git add
- Git restore
- Git log
- Commit
- Checkpoint
- Working tree
Exercise
Exercise 1:
Ask an AI agent to inspect the course folder without editing files. Then write down:
- whether the folder is a Git repository,
- which command shows changed files,
- which command shows the text diff,
- why
git restoremust be used carefully, - what a commit checkpoint means.
Exercise 2:
In a separate practice folder, ask an AI agent to create a new Git repository with git init. Ask it to create one new text file and commit it. Then ask it to change that file and commit the change. Before each commit, run git status and git diff yourself. After each commit, run git status and git log --oneline, and write down what changed.
Notes for the exercise
- Do not run a command that discards changes unless you know what it will discard.
- Do not accept a large AI-agent edit without reading the diff.
- Keep early edits small.
- For Exercise 2, use a separate practice folder, not the course repository or another important project.
- Read the diff before each commit.
- If you are using the ZIP download and not Git, make a backup copy before a large edit.