Skip to content
CodeItRaw
Git Basics

Lesson 4/4

In Git a file lives in three places: the working folder (how it is on disk), the stage (how it will go into the next commit) and the last commit. Undoing means bringing one of these back from another; to know which you want, you look at git status first.

git restore settings.json
git restore --staged keys.txt
git branch -d fix/login
git restore file throws away the change on disk and puts the file back to how it is in the last commit. git restore --staged file only takes the file off the stage; it does not touch the file on disk. git branch -d deletes a branch whose work has been merged.

Deleting a merged branch loses no work: the commits are in the history of main, and only the label is removed. Dozens of old branches left open make it hard to tell which are still alive; closing a branch when the work is done is a good habit.

Tasks

Tasks open in order. Solve them all and the next lesson opens.

This lesson's tasks open when the lessons before it are finished. You can read the explanation now.

  1. 01

    Undo

    Git task

  2. 02

    Tidy up

    Git task

If you would rather not wait for the order, every problem is open without locks: Problem list