How do I remove a bunch of file changes from a staging area in git?
So, I'm relatively new to git, and the situation I've run into a few times is that I have a copy of the code that I want, but for some reason, since I just did a "git checkout" in on several different branches of the same codebase, I get multiple files in my filesystem that don't match what is checked in my current HEAD, and so they show those files as "Changes not committed to commit" which is correct. However, I don't want to keep ANY of these changes (they are safe on some other branch).
The only way I can do this is with "git checkout -" as stated in the "git status" message.
The problem is with 10-20 files, I need to copy the filename insert 10-20 times, which is inconvenient.
Is there a better way to do what I am trying to do? I've tried "git checkout master" and similar commands without success.
source to share
If the files are "not delivered to commit", they are in the work area and not in the staging area.
If you want to forget any changes in the workspace, you can run git checkout .
, which (recursively) will bring all unset files back to an unmodified state.
Triggering git checkout .
does not affect staged changes (i.e. changes marked for commit with git add
). To disable these changes, you can run git reset HEAD <path>
(where <path>
again there could be one file, folder, or several).
The following image shows some of the states a file can be in and how to move files between these states ("index" is the same as "staging area"):
source to share
git reset --mixed
will clear your staging area of ββall files there.
Another cheat sheet (great, click on the desired section to view the commands)
source to share