AI Learning Hub › Learn AI › Self-Paced Courses › VS Code: Files, Changes, and AI Agents › Keep It, Change It, or Throw It Away

Module 7 ยท Intermediate

Keep It, Change It, or Throw It Away

Undo, Revert Change and Discard Changes sound alike and destroy different amounts of work. Staging is how you decide what a commit will contain.

By the end

  • Tell editor undo, Revert Change and Discard Changes apart by how much each destroys
  • Explain what staging decides
  • Stage one change and leave another unstaged
  • Commit deliberately, and say what the commit contains

Having read a change, you have three ways to act on it: keep it, undo part of it, or throw it away. VS Code offers operations for all three, and two of them have names close enough to be genuinely dangerous.

Three operations, three different scopes

The difference is not what they are called. It is how much work each one destroys.

Discard Changes Every edit you have made to this file since the last commit, gone at once, and the file restored to its recorded version. This is the one that can cost you an afternoon. It is a Git operation, offered on each file in the Source Control view.
Revert Change One block within a file, undone, leaving your other edits to the same file alone. Offered in the diff view beside the block it applies to. This is the precise instrument, and the one the capstone uses.
Undo Your last typing action, in the editor, the way undo works in any application. It knows nothing about Git and only covers edits made in this editing session.

Read that from the bottom up and the pattern is clear enough: ordinary undo, then one block, then the whole file. The names do not signal the difference, which is why it is worth learning once rather than discovering.

Discard Changes can destroy work that nothing will bring back. It removes edits that were never committed, which means Git has no record of them to restore. Editor undo may help if the file is still open and you act immediately, and it may not. Treat this operation the way you would treat emptying the trash: only on something you are certain about, and never as a way of tidying up a file you have not read.

Staging, and what a commit actually contains

A commit does not contain everything you changed. It contains what you staged.

This surprises people, and the surprise usually arrives in the form of a commit that quietly included a debugging file or a half-finished edit. The Source Control view makes the split visible: changes you have staged move into a group called Staged Changes, and that group is what the next commit will record. Microsoft’s own description is exactly this — select a file under Changes “to review unstaged edits, or in Staged Changes to review what the next commit will contain.”

In the Module 6 screenshot there was no Staged Changes group at all, because nothing had been staged. That is the normal starting state and the reason the group can look like it does not exist.

Staging is also where review has a natural home. Having read a diff and decided that two of three changes belong together, you can stage those two, commit them with a message describing what they are, and leave the third for a separate decision.

The exact names

Because these matter and because similar-sounding commands are the hazard, here are the labels as the current version uses them.

Source Control commands and what each one does
CommandWhat it does
Open ChangesShow the diff for this file.
Stage ChangesPut this file’s changes into the next commit.
Unstage ChangesTake them back out again. Nothing is lost.
Revert ChangeUndo one block inside a file.
Discard ChangesThrow away every edit to this file since the last commit.

Unstaging is safe and reversible, which is worth knowing because it removes the pressure from staging. Staging something is a decision you can take back.

Exercise: keep one change, undo another

Use the practice project for this and nothing else. Every step here is disposable by design.

  1. Open index.html and make two separate changes: correct the room number to 290, and in the schedule list change Closing comments to Judges’ comments. Save.
  2. Open the diff and confirm you can see both changes as separate blocks.
  3. Use Revert Change on the schedule line only. Watch the other change stay where it is.
  4. Look at the diff again. One change should remain.
  5. Stage the file, and notice it move into Staged Changes.
  6. Write a commit message saying what the change is — Correct the room number is plenty — and commit.
  7. Look at the Source Control view. What is listed now?
What you should have seen, and what to do if a step is missing

After the commit the Changes group is empty and the asterisk is gone from the branch name in the status strip, because there is no longer uncommitted work. The commit you just made appears in the history below.

If Revert Change is not offered on the block, the same result can be had by editing the line back by hand. The command appeared in the diff view in the version tested for this course, but it applies to the block your cursor is in, so put the cursor in the right one first.

If you accidentally discarded the whole file rather than reverting one block, this is exactly why the exercise uses a disposable project. Unzip the practice project again and start over — and notice how little warning you got.

What you just did is the shape of every review in this course: read the change, keep the part that was asked for, undo the part that was not, and commit with a message that describes the first and not the second.

One boundary worth naming. Everything here has been done through the interface, on one file, with no command-line Git. Branches, history, merges and anything involving another computer belong to GitHub Without the Jargon, which teaches the model this module has only been showing you the surface of.