noknow.dev
Sign inSign up
Course overview
Git — Complete Course
0 / 24 lessons0%

Git Basics

  • git init — Starting a Repository
  • git add + git commit — Your First Commit
  • git status + git log — Reading the State
  • git diff — Seeing What Changed
  • .gitignore — Ignoring Files

Branching

  • git branch + git switch — Working with Branches
  • git merge — Combining Branches
  • Resolving Merge Conflicts
  • Cleaning Up Branches

Remote Repositories

  • git remote — Connecting to a Remote
  • git push — Uploading Your Commits
  • git fetch + git pull — Getting Remote Changes
  • git clone — Copying a Repository

Undoing Changes

  • git restore — Discarding Uncommitted Changes
  • git reset — Moving HEAD Back
  • git revert — Safely Undoing a Commit
  • git stash — Temporarily Saving Work

Rewriting History

  • git commit --amend — Fixing the Last Commit
  • git rebase — Cleaner History
  • git cherry-pick — Applying Specific Commits

Advanced Tools and Workflows

  • git tag — Marking Releases
  • Mastering git log
  • git bisect — Finding Bugs with Binary Search
  • Professional Git Workflows

git reset — Moving HEAD Back

0m 00s

Going Back in History

git reset moves the branch pointer backward, optionally changing the staging area and working directory:

# --soft: move HEAD only — changes stay staged
git reset --soft HEAD~1

# --mixed (default): move HEAD + unstage — changes in working dir
git reset HEAD~1
git reset --mixed HEAD~1   # same thing

# --hard: move HEAD + discard ALL changes (dangerous!)
git reset --hard HEAD~1

When to use each

  • --soft — "I want to re-commit these changes differently"
  • --mixed — "I want to keep my changes but un-commit them"
  • --hard — "Throw everything away and go back" (cannot be undone easily!)
# Undo last commit, keep files unchanged
git reset HEAD~1

# Undo last 3 commits, keep all changes staged
git reset --soft HEAD~3

Your Task

You made two bad commits. Use git reset --soft HEAD~2 to undo both commits while keeping the file changes staged, then re-commit everything as one commit with message "Single clean commit".

Back
bashCtrl+Enter to run
Output

Click "Run" to execute your code.