how to get rid of changes to a git branch/repo/directory

WARNING: not 100%. failed for me the other day. waaah.

so, you’ve cloned a repo and played around a bit. say, for instance, you want to build a package in the current directory, and you don’t want to create a new branch- don’t want to pollute the log, history, etc. now you decide that you don’t want to keep your changes (like the generated packages). how do you revert your changes?

note, that these notes are here because i’m no git expert, and they were created from a combination of web searches, recommendations from friends, and my own tests. you have been warned. (backups are your friend.)

the following assumes that you’re in sync with the repo before you start; i.e.:

git pull && git checkout

the following two commands will revert to the original state of the directory, regardless of the branch:

  • to revert changes to modified files:

    git reset --hard
  • to remove all the new, untracked files and directories:

    git clean -ffdx