34

When I do git revert via TortoiseGit, I get this lovely window :

enter image description here

However, when I want to do the same from the command line, the documentation manages to completely confuse me. How do I revert all local uncomitted changes?

Amit Verma
  • 38,175
  • 19
  • 80
  • 104
ripper234
  • 202,011
  • 255
  • 600
  • 878
  • Just a vocabulary note: `revert` is to create a new commit that reverts a previous commit, `reset` is what you want (revert uncommited changes) – CharlesB Mar 17 '11 at 13:23
  • 2
    @CharlesB: I know they kept that as a holdover from TortoiseSVN, but man, it seems like kind of irresponsible naming. – Cascabel Mar 17 '11 at 14:49

3 Answers3

77

To discard all local changes, you do not use revert. revert is for reverting commits. Instead, do:

$ git reset --hard

Of course, if you are like me, 7 microseconds after you enter that command you will remember something that you wish you hadn't just deleted, so you might instead prefer to use:

$ git stash save 'Some changes'

which discards the changes from the working directory, but makes them retrievable.

William Pursell
  • 174,418
  • 44
  • 247
  • 279
  • Do note that this discards *all* local changes, so it's not an exact replacement for that dialog with checkboxes. If you want to throw away only some changes, use `git checkout ...` as [Marc suggests below](http://stackoverflow.com/questions/5339518/how-do-i-git-revert-from-the-command-line/5339716#5339716) – Cascabel Mar 17 '11 at 14:50
20

Assuming you haven't committed yet, you can also:

git checkout filename(s)
Marc Hughes
  • 5,688
  • 2
  • 33
  • 46
2

Git newbies like me should be aware that working directory' != pwd.

It rather means the whole tree.

So I'm thankful for Williams recommendation to use:

$ git stash save 'Some changes'

which can be undone via the following:

$ git stash pop
Dylan Corriveau
  • 2,565
  • 4
  • 27
  • 36
Joerg Rade
  • 31
  • 3