Linux, terminal and Git

Stage 5 · Lesson 8 of 8

Undoing things safely

Git fundamentals

has a different undo for each situation, so means picking the right one. git restore file throws away changes you have not staged. git restore --staged file takes a file back out of the .

git commit --amend fixes your last commit, as long as you have not pushed it. git revert <hash> adds a new commit that cancels out an old one. It is safe on other people use.

git reset moves a branch back to an earlier commit. With --hard it also throws away your work, so use it only on history nobody else has. git reflog lists everywhere HEAD has been, so "lost" commits can usually be found again.

Common trapreset --hard or force-pushing to fix a mistake on a shared branch, where revert was the safe choice.

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

Resources for this stage

Start with· follow one of these

  • BookFree
    Pro Git

    Scott Chacon and Ben Straub

    The free official Git book; chapters 2 and 3 cover everything in this stage properly

  • CourseFree
    The Missing Semester of Your CS Education

    MIT · Beginner

    The version control lecture teaches Git from its data model upwards, which makes commands make sense

Practise

Keep handy

Also worth your time

Mark this stage as not done?