University to job-ready

Stage 2 · Lesson 7 of 9

Undoing mistakes safely

Clean up your GitHub this month

can undo almost any mistake if you know which command fits. git restore throws away changes to a file you have not committed yet. git commit --amend fixes your last commit, as long as you have not pushed it.

git revert makes a new commit that undoes an old one. It is the safe choice for anything already pushed, because it adds to the shared history instead of rewriting it. git reset moves your branch back to an earlier commit and can throw work away, so use it only on commits nobody else has.

If you think you lost a commit, the (git reflog) lists everywhere your branch has been.

Common trapdeleting the folder and cloning again, which loses any work you had not pushed.

A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock

Resources for this stage

Start with· follow one of these

Practise

Keep handy

Also worth your time

Mark this stage as not done?