How to discard all uncommitted changes?

2

How to discard all uncommitted changes?

Example: I have a project that has a few dozen commits, assuming that at some point I decide to discard everything that has not yet been committed via commit , how can I do that?

Note: I want to undo everything until the previous commit. What would be the best way to do this?

    
asked by anonymous 20.08.2018 / 20:45

3 answers

4

Lists all the commits you've ever done:

git log --stat

Will list your last commits, then choose an ID, where you want to go back:

* 518ce00 
* ec3be16
* df9b821
* 8db3a02
* 698f520
* 19ccc39

Then just reset to the point you chose:

git reset --hard 19ccc39

But ideally you would work with branches, so you would avoid this.

    
20.08.2018 / 20:50
2

If you did not git add / git commit , you could simply:

git checkout .

Or delete and clone the project again

    
20.08.2018 / 21:17
2

I have successfully used only these two commands below when I make a lot of changes in a branch and I want to get rid of them all without committing anything yet .

The first command is to revert all changes to files that were versioned:

git checkout -- .

The second is to delete all files and directories created:

git clean -f -d

To the last command, you can still add -x to also delete files that were created but are being ignored by git (so they do not appear in git status ).

    
21.08.2018 / 14:01