By mistake I added some files that I didn't want to add to a commit
, I did this:
git add .
The thing is, that added all the files in the folder and there are a couple of files that I didn't want to commit because they were for my tests.
When I do this:
git status
I get:
archivo1.js
archivo2.js
archivoQueNoQuieroCommitear.js
Ask
Since I haven't done commit
how do I remove archivoQueNoQuieroCommitear.js
from the commit?
If possible I am trying to reset the head.
The files didn't exist before so I can't do them checkout
.
You must remove them from the index with:
Taken from the documentation :
So that you better understand what is happening, what the command
git add
does is add an entry to the "index" with the current content of the file in the "working tree" (your working directory).When I say add an entry to the "index", I mean that it
git add
makes a copy of your working file (the one you edited) to a "zone" known as staging (it's a folder inside the directory.git
), from where it takes the files the commandgit commit
.These are new files so they are only in the working tree and in the index, but not in the current branch, so they don't have HEAD so you won't be able to get them from there.
git reset
remove the file(s) from the "index" and only the original will remain in your working tree. Which is what you wanted.To revert specifically
git add
, it is done with:Documentation (English):
In fact I see that it is a very seen question in stackoverflow:
Revert 'git add' before a commit .
If the file is in the current directory
If the file is in a different path than the current directory
With
git reset <archivo>
you revert the file you added withgit add .
before a commit.I think it would not be good to use a git reset, since these are for removing commits or rolling back to a specific commit.
If you want to remove a file from the index (list of files that were added with add but not committed) it is better to use git rm: