You ask a coding agent to change the label on a booking button. The new label is confusing, but the note you added afterward is worth keeping. Version control lets you compare those two changes and reverse just the one that went wrong. It helps when you know what you recorded and where that copy lives.
When does Git make a save point?
A commit is a save point for your project’s files. Saving in your editor, making a commit and sending it to another copy are three different actions.
| What you do | What you can find afterward |
|---|---|
| Save in your editor | The new text is in the file on your computer. Git history may still show the old version. |
| Commit in Git | The version you prepared for the commit is in your project’s local history. Give it a message that says what changed. |
| Push to a host such as GitHub | The remote branch receives the commits you successfully send to it. Check that the expected branch and commit appear there. |
Edits you never saved may exist only in the editor. Files you save but leave out of a commit can still be on disk, and Git may show them as changed or untracked. Before trying an undo, check which of those situations you are in.
How do you tell what a commit will contain?
A repository holds a project’s files and Git history. To make a commit, first stage the changes you want to include. Staging chooses a particular version of each file. If you edit a staged file again, review and stage it again if you want the new edit in the same commit.
A diff shows the lines that were added or removed. Read the staged diff before you commit. If you expected one button label to change and the diff also shows changes to sign-in, stop and find out why. A small commit with a clear purpose makes it easier to review and reverse.
How do you try an agent’s change without changing the main branch?
Record a working version first, then make a branch for the experiment. A branch gives the experiment its own line of recorded changes. When it’s ready, read the diff and check the result before bringing it into the branch the rest of the project uses.
A branch keeps the code history separate. If a preview uses the same database or sends through the same accounts as your live app, testing the preview can still change real records or send real messages. Check those connections before you try anything that writes.
How are Git, GitHub and GitHub Desktop different?
| Tool | What it does |
|---|---|
| Git | Records and compares versions in the repository. You can make commits and branches locally. |
| GitHub | Hosts the history you send to it and gives you a place to discuss and review changes with other people. |
| GitHub Desktop | Gives you a visual way to see changed files, choose what to include in a commit and work with branches. A local commit stays local until you push it. |
You can try the exercise below with Git on your computer. It needs no GitHub account or online repository.
Can you undo one change and keep a later edit?
Try this in a new empty practice folder outside any existing Git repository, with Git installed. Use only the invented files below and leave the folder disconnected from any remote. On Windows, open Git Bash in that folder. On macOS or Linux, open a Bash or Zsh terminal there. Run git status. Continue only if Git says it can’t find a repository. If it finds one, stop and choose another folder.
1. Record the original label. Start the practice repository and prepare the first commit.
git init -b main
printf 'Book a time\n' > button-label.txt
git add button-label.txt
git diff --cached
You should see one new file with “Book a time.” The --cached flag shows what you staged. If the diff opens in Git’s viewer, you may see (END) at the bottom. Press q to return to the prompt. If the diff is right, commit it.
git commit -m "Save original booking label"
If Git asks who should be recorded as the author, run git config --local user.name "Practice" and git config --local user.email "practice@example.invalid", then retry the commit. These made-up details apply to the practice repository only.
2. Try the shorter label on a branch. Create the branch, change the same file and review what is staged.
git switch -c try-shorter-label
printf 'Continue\n' > button-label.txt
git add button-label.txt
git diff --cached
The diff should remove “Book a time” and add “Continue.” Once you see that one change, commit it.
git commit -m "Try shorter button label"
Now give yourself a later edit worth keeping. Add a note in a separate commit, then look at the branch history.
printf 'Use the longer label on the booking page.\n' > notes.txt
git add notes.txt
git commit -m "Save the follow-up note"
git status --short
git log -2 --oneline
3. Reverse only the button change. Check that git status --short printed no file changes. Copy the ID beside “Try shorter button label,” leaving the note commit alone. Replace COMMIT-ID below with that ID.
git revert --no-edit COMMIT-ID
git log -3 --oneline
Open the two files. The button label should say “Book a time” again, and the note should still be there. The log should show the original button change, the later note and a new commit that reverses the button change.
In a real project, newer work can depend on the change you reverse. Keep your current edits and review the result on a branch. If Git asks which changes to keep, check what happens when a revert overlaps newer edits before continuing.
What if the change was never committed or is already shared?
If the edit is still open in your editor, start with the editor’s undo or local history. If the file was saved but left out of a commit, inspect the current file and preserve any work you need before discarding anything. Git can recover a version it recorded. It may have no copy of the draft you never committed.
If other people already have the commit, make the correction on a branch and use your normal review and merge process. That gives the team a new commit to examine and preserves the history they already have.
Does fixing the code also fix the live app?
First identify what needs to recover. If the code is wrong, review the correction in Git. If customers still see the broken build, check which version the host is serving and use the deployment process to publish or restore the intended build. If saved bookings are missing or wrong, use the app’s data recovery process. A Git commit only records the files you chose to put in it.