Home > OS >  What's the easiest way to undo a git add
What's the easiest way to undo a git add

Time:09-23

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 .

CodePudding user response:

Run 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: Illustration of git restore

In short, in your particular case:

$ git restore --staged .

Would would move all staged changes back to your Working Tree, without the risk of any loss of data. Warning: performing restore on changes made to your Working Tree will lead to loss of data.

  •  Tags:  
  • git
  • Related