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

    Amend and reflog: rescue recent work

    Repair the last commit and understand the local safety log of HEAD movements.

    10 minutes2 games

    Forgot a small file or wrote a poor message? git commit --amend replaces the latest commit with a new one containing the current staging area. Even with similar content its hash changes because it is a new object. Use it before pushing or with team agreement.

    A—old B

    amend

    A—new B′

    reflog records the move locally

    Git
    git init -q -b main
    echo "code" > app.txt
    git add app.txt
    git commit -q -m "Ad app"
    echo "docs" > README.md
    git add README.md
    git commit -q --amend -m "Add app and docs"
    git log --format=%s

    reflog records local positions visited by HEAD and branches after commits, resets and rebases. If a reset loses a commit name, find its hash in git reflog and create a rescue branch. The simulator explains this command; practise it in a real terminal.

    Important

    Reflog is not a shared backup: it is local to each clone and entries expire. Do not replace pushing and backups with it, or amend published commits without coordination.

    Quick question

    Does --amend edit the same commit object?

    Interview question

    How do you recover a commit after reset --hard?

    Exercise

    Commit with the wrong subject Ad file, amend it to Add file, then print the subject.

    Expected output: Add file

    Git
    git init -q -b main
    echo "x" > file.txt
    git add file.txt
    git commit -q -m "Ad file"
    git log --format=%s

    Learn more from

    • Git: git-commit amendgit-scm.com
    • Atlassian: Git reflogatlassian.com

    Played 0 of 2 games

    Sign in to save your progress and earn XP.

    PreviousRevert or reset?NextRemotes, push and tracking
    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.