Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    GITGit & GitHub

    Basics: from file to commit

    • Why version control?
    • From working tree to commit
    • Read history and differences
    • .gitignore and useful commit messages

    Branches and merging

    • Branches and HEAD
    • Merge: fast-forward and three-way
    • Resolve merge conflicts
    • Park work temporarily with stash

    Undo without losing work

    • Restore and unstage
    • Reset: soft, mixed and hard
    • Revert or reset?
    • Amend and reflog: rescue recent work

    Remotes and GitHub Flow

    • Remotes, push and tracking
    • Fetch, pull and rejected pushes
    • GitHub Flow: complete project
    Git & GitHub

    Undo without losing work · Lesson 9 of 15

    Restore and unstage

    Restore a working file or remove it from staging without moving history.

    9 minutes2 games

    git restore file copies the staged version back to the working tree, discarding unstaged edits. git restore --staged file removes a change from staging while keeping it in the file. Neither moves HEAD or deletes commits.

    Last commit

    Staging

    Working tree

    restore copies backward

    Git
    git init -q -b main
    echo "safe" > note.txt
    git add note.txt
    git commit -q -m "Save note"
    echo "mistake" > note.txt
    git status -s
    git restore note.txt
    cat note.txt

    If you added something by mistake, use restore --staged first; the edit remains in the working tree. --source other-branch file retrieves one file from a chosen reference without switching the whole branch.

    Important

    git restore file is destructive for an uncommitted edit: Git cannot recover content that never entered history. Review git diff first or stash it.

    Quick question

    Remove a file from staging but keep its edit. Use?

    Interview question

    How does restore differ from old checkout usage?

    Exercise

    Commit good, change the file to bad, restore it, then print it.

    Expected output: good

    Git
    git init -q -b main
    echo "good" > app.txt
    git add app.txt
    git commit -q -m "Good"
    echo "bad" > app.txt
    cat app.txt

    Learn more from

    • Git: git-restoregit-scm.com
    • GitHub Docs: Undoing changesdocs.github.com

    Played 0 of 2 games

    Sign in to save your progress and earn XP.

    PreviousPark work temporarily with stashNextReset: soft, mixed and hard
    SeaCode

    Learn to code for real, online or at our branch in front of Cairo University, Giza.

    Learn

    • All courses
    • Interactive tutorials
    • Interview practice problems
    • Mock interview
    • Learning tracks
    • Code Arena
    • Workshops & Events
    • Knowledge library
    • Team projects

    Your account

    • Log in
    • Sign up
    • Learning plan
    • Certificates
    • Site map

    Contact us

    • WhatsApp
    • 010 9094 1104
    • In front of Cairo University, Giza

    © 2026 SeaCode. All rights reserved.