How to discard changes in Git

If you just want to clean unstaged changes on Git in your current working directory execute the following ‘Git discard all changes’ command ’:

git checkout — .

If however you are referring to a specific existing file, simply add the file path as follows :

git checkout — thepathtothefile/to/discard

Read: Git Fetch vs Pull

For newer Git releases however you would want to use the restore command :

git restore .                                         [Git discard changes command]

And for a specific file :

git restore thepathtothefile/to/discard               [Git revert changes for a file]

Answer due to Tobi.

If you like the content, we would appreciate your support by buying us a coffee. Thank you so much for your visit and support.


Nikolaus Oosterhof

Nikolaus has a degree in software development. He is passionate about gadgets with a screen, nostalgic for phones, a retired gamer and open source programmer. He likes also to write about macOS and Windows. design web pages and debug long programs!

Leave a Reply