gitpractice.dev

brewly — Ch.4 · Throw an experiment away

Exercise 3 of 9

Before you start

Really throwing away

git reset --hard <commit> moves the branch and overwrites your files to match. Uncommitted changes to tracked files are lost for good, so read git status first.

It leaves untracked files alone. git clean deletes those. -n only shows what would go, and -f does it. Ignored files such as .env are kept.

git status
what would I lose?
git reset --hard <commit>
move the branch and overwrite files
git reset --hard HEAD
only throw away uncommitted changes
git clean -n
preview which untracked files would be deleted
git clean -f
delete them
You can reopen this any time with “Lesson”.

Continue on a desktop

Typing git on a small screen is no fun. Open this page on a laptop or desktop to practise.

Back to the path