Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

git
communitycreator

How to undo "git add"

Programming Bytes

The git add command adds the changes of your current directory to the staging area.

The staging area contains changed files that are going to be a part of your next commit.

// to stage a file 
git add filename 

// to stage all changed files
git add . 

Sometimes, we may do this unintentionally, and will ned to undo this operation. For this, we can use 2 methods:

  • git reset
  • git restore --staged

Both of these methods “un-stage” the files from the staging area.

git reset

To remove a single file from the staging area:

git reset filename 

To remove all files from the staging area:

git reset

When calling reset, the changes done in to the files, before executing git add, will be available.


git restore --staged

To reset a single file from the staging area:

git restore --staged filename

To reset a single file from the staging area:

git restore --staged .

The --staged option will remove changes from the staged area and leave the file changes as is. If we don’t need the changes changes, we can remove the staged option.

RELATED TAGS

git
communitycreator
RELATED COURSES

View all Courses

Keep Exploring