How To Go Back to Previous Commits: Understanding Git Reset vs. Git Checkout

Ketan Gupta
2 min readSep 26, 2023

Introduction:

Git provides developers with powerful tools to manage version control, and two common commands for navigating your commit history are `git reset` and `git checkout`. In this tutorial, we’ll explore both methods step by step and help you understand when to choose one over the other.

Choosing the Right Method:

1. Use `git reset` when you want to make permanent changes to your commit history or reset your branch to a previous state. It’s useful for discarding changes or undoing commits.

2. Use `git checkout` when you want to explore a specific commit without affecting your branch’s history. It’s ideal for inspecting code, creating a new branch for experimentation, or temporarily working on a previous version.

Method 1: Using `git reset`

Step 1: Identify the Target Commit
Before you can use `git reset`, you need to identify the specific commit you want to reset to. Use `git log` to view your commit history and find the commit’s hash.

Step 2: Decide on Reset Type
Git reset offers three reset types: soft, mixed, and hard.
- Soft: Moves your branch pointer and staging area to the target…

--

--

Ketan Gupta

Blockchain enthusiast and writer exploring crypto, NFTs and decentralized tech. Providing fresh perspectives and thought-provoking insights. Follow for more.