How to remove files from staging in Git

Kenny DuMez
Kenny DuMez
Graphite software engineer
Try Graphite


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


Table of contents

When working with Git you may need to occasionally unstage (remove from staging) files that have been added to the staging area by mistake or that require additional modifications before they can be committed. This guide provides detailed steps on how to remove files from staging, covering various scenarios that you might encounter.

The staging area in Git, also known as the index, is where Git holds files before they are committed to the repository. When you add changes to the staging area, you are preparing them to be included in your next commit. However, if you need to make further changes or decide not to commit them, you'll need to unstage these files.

  1. Removing a specific file from staging

    If you have added a file to the staging area and need to remove it, the git reset command can be used. This command will unstage the file but leave the changes in your working directory:

    Terminal
    $ git reset HEAD <file-name>

    For example, to unstage a file named example.txt:

    Terminal
    $ git reset HEAD example.txt

    After running this command, example.txt will still contain your changes, but it will no longer be staged for the next commit.

  2. Removing multiple files from staging

    If you have several files staged and want to unstage them, you can use the git reset command without specifying a file name:

    Terminal
    $ git reset HEAD

    This command will unstage all files currently in the staging area, leaving the changes in your working directory. You can then selectively re-stage only the files you want to commit.

  3. Unstaging all changes

    In case you want to remove all files from staging, you can use:

    Terminal
    $ git reset

    This is equivalent to git reset HEAD and will unstage all changes without removing them from your working directory.

  4. Using git restore to unstage files

    Starting with Git version 2.23, you can also use the git restore command to unstage files. This command is a bit more intuitive for those familiar with other version control systems:

    Terminal
    $ git restore --staged <file-name>

    To unstage multiple files, you can repeat the command for each file, or unstage all changes using:

    Terminal
    $ git restore --staged .
  • Verify before unstaging: Always check what is currently staged before unstaging files. Use git status to review the files that are about to be committed.
  • Regular commits: Make it a practice to commit changes frequently in small logical blocks. This reduces the complexity of handling many changes in the staging area.
  • Use meaningful commit messages: When you commit staged changes, use meaningful commit messages to describe what changes have been made and why. This practice is helpful for tracking changes and understanding the history of a project.

git reset HEAD removes files from the staging area but keeps your changes in the working directory. git reset --soft HEAD~1 undoes the last commit but keeps all changes staged, essentially moving your staged changes back to the previous commit.

No, once files are committed, you cannot "unstage" them in the traditional sense. However, you can use git reset --soft HEAD~1 to undo the last commit and bring those changes back to the staging area, or git reset --mixed HEAD~1 to undo the commit and unstage the changes.

When you unstage files using git reset HEAD or git restore --staged, your actual file changes remain intact in your working directory. Only the staging status is removed - your modifications are preserved.

Yes - use git status to see which files are staged (green), modified but unstaged (red), or untracked. You can also use git diff --cached to see the exact changes that are currently staged.

Yes - you can use git reset HEAD <file> to unstage the entire file, then use git add -p <file> to selectively stage only the parts you want. The -p flag allows you to interactively choose which hunks to stage.

This selective staging approach works well with conventional commits to create more focused, meaningful commits.

Both commands do the same thing - unstage files while preserving changes. git restore --staged is newer (introduced in Git 2.23) and was designed to be more intuitive. git reset HEAD is the traditional method and works in all Git versions. For more advanced Git branching strategies and workflows, see our guide on advanced Git branching strategies.

No, unstaging files only affects what will be included in your next commit. It doesn't change any existing commits or commit history.

You can use git add <file> to re-stage any files you accidentally unstaged. Your changes are still there in your working directory.

For further reading on unstaging files in Git see the official Git documentation.

Git inspired
Graphite's CLI and VS Code extension make working with Git effortless.
Learn more

Built for the world's fastest engineering teams, now available for everyone