---
title: "How do I undo git add before committing?"
description: "Staged a file by mistake? Use git restore --staged to take it out of the index without losing your edits, plus the older git reset form and what to do in a new repo."
url: https://www.danny.engineering/answer/git/how-do-i-undo-git-add-before-committing
author: Danny
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T18:58:00.000Z
tags: ["Git"]
---

# How do I undo git add before committing?

## The short answer


Run `git restore --staged` with the file name. It takes the file out of the staging area (the index) and leaves your edits in the working tree exactly as they were. Nothing is lost; the file just goes back to being a normal unstaged change.


```bash
git restore --staged src/config.ts   # unstage one file
git restore --staged .               # unstage everything
```


## Why it happens


Git has three places a change can live: your working tree (the files on disk), the index (what will go into the next commit) and the commit history. `git add` copies the current version of a file from the working tree into the index. It does not commit anything.


So "undoing" `git add` means making the index match the last commit again for that file, while leaving the working tree alone. That is exactly what `git restore --staged` does: it restores the index entry from `HEAD`.


The usual ways people end up here:

- Running `git add .` or `git add -A` and catching files you did not mean to include, such as a local config file or a debug log.
- Staging a file, then deciding the change belongs in a separate commit.
- Adding a large generated file and noticing before you commit.

If you run `git status`, Git even prints the command for you under "Changes to be committed".


## How to fix it


### Use git restore --staged


This is the modern, clearest command, available since Git 2.23.


```bash
git status
# Changes to be committed:
#   (use "git restore --staged <file>..." to unstage)
#         modified:   src/config.ts
#         new file:   debug.log

git restore --staged debug.log
git status
# debug.log is now listed under "Untracked files" again
```


You can pass several paths or a directory. To unstage only some hunks of a file, add `-p` and Git will ask about each one:


```bash
git restore --staged -p src/config.ts
```


### Use git reset on older Git versions


Before `git restore` existed, the standard way was `git reset` with a path. It still works and does the same thing for this case.


```bash
git reset src/config.ts        # unstage one file
git reset                      # unstage everything
```


With a path and no mode flag, `git reset` only touches the index. It does not move your branch and does not change files on disk.


### In a brand new repository with no commits


Both commands above restore the index from `HEAD`. In a repository where you have not made the first commit yet, there is no `HEAD`, so use `git rm --cached` instead:


```bash
git rm --cached debug.log      # remove from the index, keep the file on disk
git rm -r --cached .           # unstage everything in a new repo
```


### Stop it happening again


If the file should never be committed, add it to `.gitignore` so `git add .` skips it in future:


```bash
echo "debug.log" >> .gitignore
```


It also helps to review before staging with `git add -p`, which shows each change and asks whether to include it.


## Common pitfalls

- Leaving out `--staged`. Plain `git restore file` throws away your working tree changes to that file, which is a different and destructive operation.
- Reaching for `git reset --hard`. That unstages everything but also discards all uncommitted edits in tracked files.
- Using `git rm --cached` on a file that is already committed. In an existing repository this stages the file's deletion, so your next commit removes it from the repository. Use `git restore --staged` instead.
- Expecting unstaging to undo a commit. If you have already committed, you need `git reset --soft HEAD~1` or a similar command, not `git restore --staged`.

## Related reading

- [Git documentation: git restore](https://git-scm.com/docs/git-restore)
- [Git documentation: git reset](https://git-scm.com/docs/git-reset)
