How to Undo a Git Add Before Commit


Scenario A: You Have Commits Previously
1
$ git reset <file>

or equivalently

1
$ git reset HEAD <file>

The above command will:

  • Remove the file from the current index (the “about to be committed” list) without changing anything else
1
$ git reset

The above command will:

  • Remove all files from the current index. This is handy if there are too many files to be listed one by one.
Scenario B: You Do Not Have Any Commits Yet (A New Repository)
1
$ git rm --cached <file>

The above command will:

  • Remove (unstage) the file from the current index.
1
$ git rm -r --cached .

The above command will:

  • Remove all files from the current index.




Related Posts

What is the Difference Between Git Pull and Git Fetch

Short answers to the question what is the difference between...

How to Revert a Git Repository to a Previous Commit

Short answers to the question how to revert a git...

How to Modify Existing Unpushed Commit Messages

Short answers to the question how to modify existing unpushed...

How to Undo a Git Add Before Commit

Short answers to the question how to undo a git...

How to Rename a Local Git Branch

Short answers to the question how to rename a local...

How to Delete a Git Branch Locally and Remotely

Short answers to the question how to delete a git...