Undo Git mistakes

Throw away changes you haven't committed

Put files back to how they were at the last commit, and remove new files you don't want.

Fill these in once
  1. See what changed
    Terminal
    git status
  2. Undo the changes to one file
    Terminal
    git restore index.html
  3. Undo the changes to every file
    Terminal
    git restore .
  4. Preview the new files that would be deleted
    Terminal
    git clean -nd
  5. Delete those new files
    Terminal
    git clean -fd

    Gone for good, so check the preview first.

Check it worked

  1. Check nothing is left
    Terminal
    git status
  1. See what changed
    Terminal · Ubuntu / Debian
    git status
  2. Undo the changes to one file
    Terminal · Ubuntu / Debian
    git restore index.html
  3. Undo the changes to every file
    Terminal · Ubuntu / Debian
    git restore .
  4. Preview the new files that would be deleted
    Terminal · Ubuntu / Debian
    git clean -nd
  5. Delete those new files
    Terminal · Ubuntu / Debian
    git clean -fd

    Gone for good, so check the preview first.

Check it worked

  1. Check nothing is left
    Terminal · Ubuntu / Debian
    git status
  1. See what changed
    PowerShell
    git status
  2. Undo the changes to one file
    PowerShell
    git restore index.html
  3. Undo the changes to every file
    PowerShell
    git restore .
  4. Preview the new files that would be deleted
    PowerShell
    git clean -nd
  5. Delete those new files
    PowerShell
    git clean -fd

    Gone for good, so check the preview first.

Check it worked

  1. Check nothing is left
    PowerShell
    git status