How to undo git add before commit

How to undo git add before commit

In this article lets understand how to undo git add before commit.

There are times when we have added few files via git add and not committed yet and now we don’t need to stage them for commit.

So, we can do this using “git reset” command.

Let’s understand how to do that step by step:

1 ) check status

Hit above command to see which files you have already added in last git add. This will give you list of modified files added.

git status

2 ) Use the git reset

Now we will use this specific command to remove the staged files we added via git add.

In this case you will have to scenarios :

  1. Remove specific file
  2. Remove all the files

Lets check both one by one.

1) Remove specific file

To remove specific file from the list of files use below command:

git reset file_path

Use file_path with your actual file destination.

2) Remove all the files

To remove all the files you can simply use below command without mentioning any path. This will un-stage all the files from the list:

git reset  

When you use git reset it will un-stage the files but these files will still be modified .

Check stage again

Check the status of files again after git reset to verify the status of files. You must see list of modified files but unstaged.

git status

Now you can make the modifications and proceed as needed.

That’s all on how to undo git add before commit. Hope this find you helpful.

Read more articles on git here.