How To Undo `git add` Before Commit

Let's say you've accidentally added files to Git that you didn't mean to like this:

git add wrong-file.txt

This is called "staging" the files.

If you haven't comitted with git commit yet and you want to undo this ("unstage" the files) then you can simply do this:

git reset wrong-file.txt

This will take you back to the point before you added the wrong file to be committed, allowing you to start again.

If you want to unstage all of the changes, not just one file, you can simply do:

git reset

Hosted Gitea is a fully managed Gitea hosting service. If you're looking for a private alternative to GitHub or Gitlab check out our service.

Get your Gitea server