How do I remove a staging area file in git?

Asked

Viewed 9,290 times

7

I accidentally added all the files to the staging area of git with the "git add." , how to remove a file from staging area so it is not commited?

1 answer

10


As mentioned in the message of git status (use "git reset HEAD <file>..." to unstage), the command is:

git reset HEAD <file>...

If you want to remove a file:

git reset HEAD caminho/para/o/arquivo

If you want to clean up the whole staging, go to the repository root directory and use the command:

git reset HEAD *
  • 2

    One way to avoid accidents like this in the future is to add the files incrementally with the command git add -p (patch mode). This allows you to add each change individually. (User suggestion @mollusk: Thank you! I preferred to add as a comment rather than include in the reply.)

  • 1

    About how to avoid accidents, I think git add -u is closer to the desired result. Does not add new files and does not ask for confirmation of each modified snippet.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.