How to undo git add before commit?

git reset file_name

To undo git add before a commit use git reset file_name, with the selected path or file as a parameter.

After this you can commit the remaining changes in your staging area.

Layer 1
Terminal Example
git status
On branch main
Changes to be committed:
  (use "git restore --staged ..." to unstage)
    modified:   README.md
git reset README.md
Unstaged changes after reset:
M README.md
git status
On branch main
Changes not staged for commit:
  (use "git add ..." to update what will be committed)
  (use "git restore ..." to discard changes in working directory)
    modified:   README.md

no changes added to commit (use "git add" and/or "git commit -a")

See git reset to learn more about it.

Last modified on November 30, 2021.

You might also like