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 11 of 15

    Revert or reset?

    Revert adds a safe correction; reset rewrites the branch line.

    10 minutes2 games

    git revert X does not erase X; it creates a new commit with the inverse change. That is safe after pushing because everyone can pull the new history. reset moves a branch name backward, potentially hiding published commits from its visible line.

    A—B—C (bug)

    revert adds D inverse to C

    history preserved

    Git
    git init -q -b main
    echo "safe" > app.txt
    git add app.txt
    git commit -q -m "Safe"
    echo "bug" > app.txt
    git commit -q -am "Bad change"
    git revert HEAD
    cat app.txt

    A simple choice: published or shared commit? Revert it. Private local commit that nobody relies on and history needs reshaping? Reset may fit. If a revert conflicts, resolve it like any other conflict.

    Important

    Do not routinely push --force after resetting main; it can erase teammates' commits. If an agreed branch rewrite is unavoidable, fetch and use --force-with-lease with explicit coordination.

    Quick question

    A bug reached main and others pulled it. Best choice?

    Interview question

    Does revert restore the whole project to an old snapshot?

    Exercise

    After a safe commit and a bug commit, reverse the latest commit and print the file.

    Expected output: safe

    Git
    git init -q -b main
    echo "safe" > app.txt
    git add app.txt
    git commit -q -m "Safe"
    echo "bug" > app.txt
    git commit -q -am "Bug"
    cat app.txt

    Learn more from

    • Git: git-revertgit-scm.com
    • GitHub Docs: Reverting a commitdocs.github.com

    Played 0 of 2 games

    Sign in to save your progress and earn XP.

    PreviousReset: soft, mixed and hardNextAmend and reflog: rescue recent work
    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.