Skip to content

git reset

Overview

git reset is the command to reset current HEAD to the specified state

  • git reset --soft HEAD~N Removes the last N commits from history but keeps the file changes (your code stays the same).

  • git reset --hard HEAD~N Removes the last N commits and deletes the file changes — this resets your codebase to an earlier state.

✅ If You Want a Fresh Start (One New Commit)

You don’t need to count commits. Instead, you can:

Option 1: Start Fresh from Current Code

git checkout master
git checkout -b fresh-branch
git reset $(git rev-list --max-parents=0 HEAD)
git add .
git commit -m "Fresh commit with latest code"

What this does:

  • Creates a new branch
  • Resets to the very first commit (no need to count)
  • Adds all current files
  • Makes one clean commit

Option 2: Delete History and Keep Code

rm -rf .git
git init
git add .
git commit -m "Fresh start"

Warning: This deletes all Git history and starts a brand-new repo. Use only if you truly want to wipe everything.