Situation: I have a Git repository with files already in the index. I make changes to several files, open Git and add these files to my staging area with "git add ."
Question: How do I remove one of those files from the staging area but not remove it from the index or undo the changes to the file itself?
You want:
Affect to a single file
Remove file from staging area
Not remove single file from index
Don't undo the change itself
and the solution is
or
To unstage everything at once, run this command
You need to be in the directory of the file and then type the following into the terminal
Assumption is that you need to reset one file only.
In case you just want to remove a subset of the changes to your file, you can use:
or
This command is basically the reverse of
git add -p
: it will only remove the selected changes from the staging area. I find it extremely useful in "unadding" something that I added by mistake.If you want to remove files following a certain pattern and you are using
git rm --cached
, you can use file-glob patterns too.See here.
In my case, I do