Git Reset Head 2

Published
Length
3 min read

Luis Felipe Dias

All posts

Running git reset head 2 moves your current branch pointer back by two commits. This action undoes your last two snapshots in your local version history. Teams use this workflow to fix bad commits or combine messy local work. Problems start when broad branch permissions let engineers push altered history to shared codebases. How git reset head 2 changes local commit history Git tracks your work through three main local areas on your machine. The first area is the commit history where Git stor

Git Commit Signing (GPG, SSH): the complete guide

Architecture patterns, implementation strategies, and security best practices. Delivered to your inbox.

Free white paper. No spam. Unsubscribe anytime.

Running git reset head 2 moves your current branch pointer back by two commits. This action undoes your last two snapshots in your local version history. Teams use this workflow to fix bad commits or combine messy local work. Problems start when broad branch permissions let engineers push altered history to shared codebases.

How git reset head 2 changes local commit history

Git tracks your work through three main local areas on your machine. The first area is the commit history where Git stores saved snapshots. The second area is the staging index where you prepare files for the next save. The third area is your working folder where you edit raw files.

When you run git reset head 2, you target the commit two steps back. The head pointer marks your latest commit on the active branch right now. Moving that pointer back two steps takes two commits off the current branch tip. How Git handles the file changes from those two commits depends on your reset mode.

A soft mode moves the branch pointer back two commits and stops there. It leaves all file changes from those two commits inside your staging index. Your working folder stays untouched, and your edits sit ready for a fresh commit. Teams use soft mode to squash two small commits into one clean snapshot.

A mixed mode is the standard behavior when you do not pick a mode. It moves the branch pointer back two commits and clears the staging index. Your file edits stay safe inside your working folder as unstaged local changes. You can review the files, make fixes, and stage only what you want.

A hard mode resets the branch pointer, the staging index, and the working folder. It wipes out all uncommitted work and deletes changes from the last two commits. Your local files match the exact state of the commit from two steps ago. Engineers must check their status before running a hard reset to avoid losing work.

What branch rules solve and what they leave open

Rewriting commit history works well when those commits only exist on your laptop. Once you push commits to a remote server, other people pull that same history. If you reset two commits and force push, you break the branch for teammates. Their local histories will clash with the altered remote branch during their next pull.

Git Commit Signing (GPG, SSH): architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Source control platforms use branch protection rules to stop forced history changes on shared branches. Admins lock down main branches so standard developer roles cannot force push altered history. Teams also require pull request reviews before anyone merges new code into production branches. These native settings control who can push code and which branches accept history rewrites.

Still, source control permissions only govern git actions and branch logins at the repo level. They do not inspect what happens when engineers run commands against live servers or databases. A developer who fixes a bad commit might still need to fix production state. Repo roles decide who logs in, not what individual statements or commands do in flight.

Safe ways to undo commits on shared branches

When bad commits already sit on a shared branch, avoid resetting the branch pointer. Use a revert workflow instead of moving the head pointer back two steps. A revert creates a brand new commit that reverses the changes from earlier commits. This approach keeps the shared history intact so teammates can pull updates without conflicts.

Save git reset head 2 for private feature branches that only you touch. Check your commit log first to confirm which two snapshots sit at the tip. If you ever run a hard reset by mistake, check the local reference log. Git keeps temporary records of old commits there so you can recover lost work.

Check database and API queries on the wire

Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev runs beside those services as an open-source proxy, a sidecar for your Postgres or API. It inspects requests coming in and results going back on the wire.

Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run. On responses, hoop.dev data masking rewrites matched sensitive values in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.

Frequently asked questions

Does git reset head 2 delete my local file edits?

No, standard mixed mode and soft mode both keep your file edits on disk. Only the hard reset mode deletes changes from your working folder and staging index.

Can I recover commits after running a hard reset back two steps?

Yes, you can look up the old commit ID in your local reference log. Once you find that ID, you can reset your branch back to that snapshot.

When should I use revert instead of resetting two commits?

Always use revert if you already pushed the last two commits to a shared branch. Revert adds a new undo commit so you do not break history for teammates.

Save the open-source gateway.

hoop is MIT-licensed infrastructure for controlling how AI agents reach production data. Star hoophq/hoop so you can inspect it, deploy it, or share it when your team starts governing agent access.