dev.log / syntax diaries

Practical code notes, tools, and guided learning for developers.

Practical guides, developer tools, and tutorials for modern web developers, with the same focused tone across writing, utilities, and learning tracks.

BlogToolsTutorialsAboutContactAdmin Login
Privacy PolicyTerms of ServiceCookie Policy

© 2026 The Syntax Diaries · System_Operational

The Syntax Diaries logoThe Syntax Diaries
BlogToolsTutorialsAbout
build log live
Tutorial / Git
Advanced30 minutesadvanced

Reset and Revert

Master Git reset and revert operations for effective history management

On This Page

Learning ObjectivesUnderstanding Reset vs RevertGit ResetGit RevertTypes of ResetSoft ResetMixed ResetHard ResetUsing Git RevertBasic Revert OperationsImportant NoteRecovery StrategiesRecovering from Hard ResetFixing a Bad RevertRecovering Staged ChangesBest PracticesWhat's Next?

Reset and Revert#

Master Git reset and revert operations for effective history manipulation and error recovery.

Learning Objectives#

  • Understand the differences between reset and revert operations
  • Master the three types of reset: soft, mixed, and hard
  • Learn when and how to use revert for safer history modification
  • Implement effective recovery strategies for common scenarios

Understanding Reset vs Revert#

Git provides two main ways to undo changes: reset and revert. While both help you handle unwanted changes, they work very differently and are used in different scenarios.

Git Reset#

            - •

                Moves the branch pointer to a different commit
            - •

                Can modify working directory and staging area
            - •

                Best for local changes not yet pushed

Git Revert#

            - •

                Creates new commit that undoes previous changes
            - •

                Preserves history and is safe for shared branches
            - •

                Best for published changes that need to be undone

Types of Reset#

Git reset comes in three flavors, each affecting different areas of Git's state management:

Soft Reset#

Only moves HEAD pointer, leaving staging area and working directory unchanged.

$ git reset --soft HEAD~1

Mixed Reset#

Updates HEAD and staging area, leaves working directory unchanged.

$ git reset HEAD~1

Hard Reset#

Updates all areas, discarding all changes since the target commit.

$ git reset --hard HEAD~1

Using Git Revert#

Git revert is the safer option for undoing changes, especially in shared repositories. Let's look at how to use it effectively:

Basic Revert Operations#

Important Note#

When reverting merge commits, you must specify which parent to revert to using the -m flag. Usually, -m 1 reverts to the main branch's parent.

Recovery Strategies#

Having a good recovery strategy is crucial when working with reset and revert. Here are some common scenarios and their solutions:

Recovering from Hard Reset#

              `}
                variant="shell"
              />

Fixing a Bad Revert#

Recovering Staged Changes#

Best Practices#

          - Always use revert for changes that have been pushed to remote repositories

              Use reset primarily for local changes and cleanup

              Always check git reflog before performing destructive operations

              Consider creating backup branches before major history modifications

What's Next?#

        Now that you understand how to modify history safely with reset and revert, you're ready
        to dive deeper into Git's internals. In the next lesson, you'll learn about:

              Git's object model and how it stores data
          - Understanding refs and refs of refs
          - How Git manages and optimizes storage with packfiles

Previous

Tags and Releases

Next

Git Internals