git > discard local changes (no return!) with reset — hard

The concern is documenting removing all the changes done in the working area of the git repo. Beware: this is about resetting uncommitted changes, there no return — you just burn it for good. So be sure you know what you’re doing.

1. condition: no commit no reset

  • you can reset changes to what has been committed
  • so you can reset modification or removal
  • if you, however, add/create a new file and do not commit it, git reset --hard does logically nothing with it
  • the same for branches -> you cannot reset the creation of a branch

2. use-cases

  • clone/pull → mess up a file → immediately want to return to the state of the pull
  • clone/pull/commit → delete a file by mistake in a working area → restore it right away

3. command

Originally published at github

Written by

today I learnt… | as a support eng of the wonderful Snowplow Analytics, expect everything around modern (postmodern?) business intelligence

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store