Skip to content
Author: ytianle (63.89%), ytianle (36.11%)

Cancel Add, Cancel Edit⚓︎

This guide helps you cancel added or edited files in Git.

Cancel Added Files⚓︎

If you have added files to the staging area using git add but want to unstage them, you can use the following command:

terminal
git reset HEAD --<file_name> # Unstage a specific file from the staging area to the working directory (1)
  1. git reset by default uses --mixed which unstages the file but keeps the changes in the working directory. Refer to Git Reset Documentation for more details.

Cancel File Edits⚓︎

If you want to discard local edits to tracked files:

terminal
git restore <file_name> # Discard edits in working tree for a specific file
or
git restore . # Discard edits in working tree for all tracked files

If you want to remove untracked files and directories:

terminal
git clean -fd # (1)
  1. -f stands for force (required to actually delete the files, otherwise nothing will be removed), -d stands for directories. Only removes untracked files/dirs.