Author:
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)
- git reset by default uses
--mixedwhich 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:
-fstands for force (required to actually delete the files, otherwise nothing will be removed),-dstands for directories. Only removes untracked files/dirs.