Git Reset Commands

Published
Length
3 min read

Luis Felipe Dias

All posts

You run git reset commands to move your current branch pointer to another commit. This action undoes local changes in your commit history, staging area, or working directory. Most teams let developers run these actions freely on local feature branches. Still, broad permissions on shared branches let one bad reset erase work for the whole team. How git reset commands work across your trees Version control tracks your code across three separate areas on your local machine. First, the commit his

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.

You run git reset commands to move your current branch pointer to another commit. This action undoes local changes in your commit history, staging area, or working directory. Most teams let developers run these actions freely on local feature branches. Still, broad permissions on shared branches let one bad reset erase work for the whole team.

How git reset commands work across your trees

Version control tracks your code across three separate areas on your local machine. First, the commit history stores your saved snapshots inside the repo folder. Second, the staging index holds the changes you plan to put into your next commit. Third, the working directory holds the actual files you edit on your screen.

When you run git reset commands, you pick one of three main modes. A soft reset moves your branch pointer back to an earlier commit snapshot. It leaves your staging index and your working files untouched so you can commit again. Developers use this mode when they want to combine several small commits into one.

A mixed reset is the standard mode when you do not pick an option. It moves the branch pointer back and also clears your staging index to match. Your modified files stay safe inside your working directory so you can review them. You can then choose which file changes to stage again for your next snapshot.

A hard reset is the most destructive option among the three modes. It moves the branch pointer, clears the staging index, and overwrites your working directory files. Any uncommitted local changes in your tracked files disappear right away. Teams must use extreme care before they run a hard reset on active work.

Choosing between reset and revert on shared branches

Local work and shared work need very different rules for undoing code changes. A reset rewrites the commit history by moving the branch tip to an older snapshot. That works well when the commits only exist on your own laptop. Nobody else has pulled those commits yet, so changing the history breaks nothing.

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

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Trouble starts when a developer resets a branch and forces that change to a shared server. Other team members who already pulled the old history now have conflicting branch states. Their next push or pull will merge old commits back in or fail outright. For shared branches, a revert action is much safer because it adds a new commit.

What native branch rules solve and what they miss

Hosting platforms give teams branch protection rules to stop forced history changes on main branches. You can block force pushes and require peer reviews before anyone merges new code. These settings decide who can log in and push updates to a protected branch. They stop accidental history rewrites on your central code server.

Still, repo branch rules only check git actions when code reaches the remote server. Developers still run powerful tasks against live servers, databases, and cloud tools during daily work. Repo permissions decide who logs in to code hosts, not what live operational commands do. When an engineer connects to a production system to fix a bad deploy, branch rules do nothing. Teams still face huge risks when someone runs an unchecked command during an incident.

Govern statements and responses across databases and APIs

Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev runs beside each supported service as an open-source proxy, a sidecar for your database or API.

First, hoop.dev guardrails block banned queries before they run. Then hoop.dev data masking rewrites matched sensitive values in responses in memory. The audit trail records every statement and verdict per resource. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.

Frequently asked questions

Can I recover commits after a hard reset?

Yes, you can often recover committed snapshots by checking the local reference log. Version control keeps a local log of where your branch pointers pointed over recent days. You can find the old commit identifier in that log and move your branch back. Uncommitted file edits that you never staged or saved cannot come back this way.

What happens to untracked files during a reset?

Standard reset modes only touch files that your repo already tracks in its history. New files that you never staged stay in your working folder even during a hard reset. To remove untracked files and folders, you must run a separate clean action.

When should I use a soft reset?

Use a soft reset when you want to redo your last few local commits cleanly. It moves the branch pointer back while keeping all your code edits staged and ready. You can then write one clean commit message for the whole batch of changes.

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.