How do you undo
git add . without losing the changes made on local?
I wanted to
git add './file1.java './file2.java' but instead did
git add .
git reset to unstage all pending changes from the local index.
This does not alter your local files at all, it just resets your local git index and is safe to run.
If there are only particular directories you want to unstage then you can pass a pathspec:
$ git reset -- ./some/path
Only files under that path will be unstaged, everything else will remain staged in the index.
Although it’s a bit technical, this is discussed in the git documentation: https://git-scm.com/docs/git-reset
This means that
git reset <pathspec>is the opposite of
git add <pathspec>. This command is equivalent to
git restore [--source=<tree-ish>] --staged <pathspec>....
For example, after running these two commands it has no net effect – the local index will end up back where it started:
$ git add . $ git reset .
Answered By – Sly_cardinal
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0