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

    Basics: from file to commit · Lesson 3 of 15

    Read history and differences

    Use log, show, diff and diff --staged before judging or committing changes.

    10 minutes2 games

    git log --oneline summarizes history, git show explains a commit, and git diff asks what changed but is not staged. git diff --staged reviews the proposed next snapshot.

    CommandWhat it compares

    git diff

    working tree ↔ staging

    git diff --staged

    staging ↔ last commit

    git show

    A commit and its patch

    git log --oneline

    History summary

    Git
    git init -q -b main
    echo "red" > colors.txt
    git add colors.txt
    git commit -q -m "Start colors"
    echo "blue" >> colors.txt
    git diff
    git add colors.txt
    git diff --staged

    A - line belongs to the old version and a + line to the new one; the markers are not file content. Compare branches or commits with git diff ref1 ref2.

    Important

    A plain git diff may be empty because all changes are staged. Use git diff --staged, and let status identify the area.

    Quick question

    After git add, which command shows the next commit's content?

    Interview question

    What is the difference between git diff and git show?

    Exercise

    Make two commits named Chapter one and Chapter two, then print subjects newest first.

    Expected output:
    Chapter two
    Chapter one
    Git
    git init -q -b main
    echo "one" > story.txt
    git add story.txt
    git commit -q -m "Chapter one"
    git log --format=%s

    Learn more from

    • Git: git-diffgit-scm.com
    • Atlassian: Git diffatlassian.com

    Played 0 of 2 games

    Sign in to save your progress and earn XP.

    PreviousFrom working tree to commitNext.gitignore and useful commit messages
    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.