Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to quickly undo staged and unstaged changes in git?

Tags:

git

What's the quickest way to undo changes (staged and unstaged) in Git?

Both files unstaged.

$ git status -s  M file1.txt # unstaged ?? oops.txt # unstaged 

One file staged, one file unstaged.

$ git status -s M  file1.txt # staged ?? oops.txt # unstaged 

I can add all to index and then stash save and drop.

$ git add . $ git stash save $ git stash drop $ git status nothing to commit, working directory clean 

Is there a quicker way?

like image 358
hIpPy Avatar asked Apr 23 '13 03:04

hIpPy


People also ask

How do I get rid of staged changes in git?

Discard Staged Changes With Git Reset We can use git reset with --hard to discard staged files. After running the git reset command, all the changes of the staged files including the newly created and existing files will be discarded.

How do you undo a staged commit?

Staged files are those which go into your next commit. If you accidentally added files to the staged area, you can undo this by typing git restore --staged <file> , so in this case, it would be git restore --staged lib.

How do I restore unstaged changes?

For all unstaged files in current working directory use: git restore . That together with git switch replaces the overloaded git checkout (see here), and thus removes the argument disambiguation. If a file has both staged and unstaged changes, only the unstaged changes shown in git diff are reverted.


1 Answers

git reset HEAD git checkout . 

git reset HEAD will unstage all changes and git checkout . discards all the changes.

like image 143
Nima Avatar answered Oct 06 '22 07:10

Nima