Programming foundations

Stage 2 · Lesson 8 of 8

stash, log and undoing mistakes

Command line and Git

is a skill of its own: everyone makes mistakes, and the trick is picking the right undo. git stash puts uncommitted changes on a shelf so you can switch , and git stash pop brings them back. git restore file throws away your edits to a file, and git restore --staged file takes it out of the .

git commit --amend fixes the last commit's message or adds a forgotten file, before you push. git revert makes a new commit that undoes an old one, and it is the safe choice on history others share. git reset moves your branch back.

With --hard, it also throws work away, so use it only on commits you have not pushed. git log and git reflog (a of where your branch has been) help you find what you think you lost.

A question to check yourself, an AI practice session and 1 cheat sheet entry come when you add the roadmap to your account. Add it

Resources for this stage

Start with· follow one of these

Practise

  • Draws the commit graph as you type, so merge and rebase stop being a mystery

  • Levels 0 to 15 build real shell reflexes: finding files, reading them, permissions

Keep handy

  • Free official book: read chapters 1 to 3, keep the rest for later

  • Recovery recipes for the day a commit goes wrong

Also worth your time

Mark this stage as not done?