ripper234
ripper234

Reputation: 230038

How do I git-revert from the command line?

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?

Upvotes: 34

Views: 43142

Answers (3)

Joerg Rade
Joerg Rade

Reputation: 31

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

Upvotes: 2

Marc Hughes
Marc Hughes

Reputation: 5858

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

git checkout filename(s)

Upvotes: 20

William Pursell
William Pursell

Reputation: 212248

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.

Upvotes: 77

Related Questions