Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

Git Tutorial 30 – Understand Soft, Mixed And Hard Options Of Git Reset

Posted on 02/19/2025 By admin

As a part of GIT Tutorials End To End, we will learn about –soft, –mixed and –hard options of the git reset command.

I will expect that you are aware of the basic concepts and commands of GIT. But if you are a beginner in GIT then I strongly recommend you to refer GIT Basic Commands and Concepts section on my blog first.

I have already covered the basic usage of the git reset command in this post. In this post, we will see a detailed explanation of the –soft, –mixed and –hard options of the git reset command.

We have already learned about Working Directory, Staging or index area and Remote or HEAD. I will give a quick recap of these terms here. I would like to give a real-time example here to make you understand better.

You work as a Fruit vendor and you are famous for selling good quality fruit in the market. You produce fruit on your farm (Working Directory). Since you sell only good quality fruits, you choose the best from the farm and keep them aside (Staging Area). You pack all good fruits in one or more boxes (Commits) and load them in a truck (Local Repository).

We create a new git repository or clone an existing repository in local. We can add/delete/modify files in these repositories. Initially, all these changes are in the local working directory. For example, If we add a file to this git repository then the git status command will immediately reflect changes. So any change in the repository will be in the working directory first.

When we make any changes in the git repository that will be in the working directory first. If we think that this change should go as a commit to the repository then we need to add this change to another intermediate area called staging or index area. We use the git add command to add changes from the working directory to the staging area. We can always remove changes from the staging area as well. Remember that adding changes to the staging area does not mean that it will be removed from the working directory.

Once we have added changes to the staging area then these changes are ready to be part of the next commit and can be pushed to the remote repository (GitHub/BitBucket etc). Once we do commit then the HEAD of the local branch will be updated. After pushing the commit, the HEAD of the remote branch will also be updated.

Git reset command is used to reset HEAD or undo a commit. We have three options to use with the git reset command – soft, mixed and hard in which mixed is the default option. Before we go into detail let’s create a git repo with some commits. I will not push these to the remote repo as of now.

The status of the above git repository can be shown in the image below –

So above we have two commits and want to reset/undo the last commit. How we want to undo that depends on the option we choose.

So the process is to add the change to the staging directory from the working directory and commit it before pushing it to the remote repository. If you would like to just undo the commit command and do not want any change in the working directory and staging area then use the –soft option. In the last commit, I added the second line in fileA.txt and then used the git add command to add the change in staging and then used the git commit command to commit. The git reset command with the –soft option will just undo the last command i.e. git commit. You will be in the same position after you used the git add command or before the git commit command. The changes done as part of the second commit will be present in the working directory and staging area.

Let’s do this in action –

You can see that after running the git reset command with the –soft option, the last commit disappeared/was undone but changes are still in the staging area and working directory. HEAD is set to the previous commit i.e. first commit in my case above.

If we want to go one step back further from what we have done in the git reset –soft above then we should use the –mixed command. This option will undo the git commit and git add command. In short, the state of the staging area will be the same as the local repository. The changes done as part of the second commit will be present only in the working directory.

Let’s do this in action. Please note I have restored the repository status as in beginning.

You can see the last commit and git add commands were undone and changes are still in the working directory but not in the staging area.

If we want to go one step back further from what we have done in the git reset –mixed above then we should use the –hard command. The –hard option will remove all changes done as part of the removed commit. The contents of the local repository, staging area and working directory will be the same.

Let’s see this in action –

You can see above that all changes done as part of the second commit were removed. HEAD is set to the previous commit i.e. first commit in our case.

The git reset command with any option will reset HEAD. So –

  1. If you just want to reset HEAD and keep staging and working directory as it is then use the –soft option.
  2. If you want to reset HEAD and staging area but the working directory as it is then use the –mixed option.
  3. If you want to reset HEAD, staging and working directory then use the –hard option.

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe to my YouTube channel.
#ThanksForReading
#HappyLearning

Uncategorized

Post navigation

Previous Post: Log4j2 Tutorial 6 – Introduction to RollingFileAppender and its Triggers and Strategies
Next Post: REST Assured Tutorial 4 – Let’s Write First GET REST Assured Test

Related Posts

April 15, 2017 – Make Selenium Easy Uncategorized
TestNG Tutorials 5: How To Create And Run A TestNG Class Uncategorized
image – Make Selenium Easy Uncategorized
Collections in postman Uncategorized
TestNG Tutorials 42: Parameters In TestNG or Parameterization of Methods in a TestNG Class | Make Selenium Easy Uncategorized
Java Programs 14: Java Program to Print Fibonacci Series of Given Length Using Recursion Uncategorized

Recent Posts

  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing
  • Baby Steps To Become Efficient Selenium-Java Automation Tester
  • Features of Selenium 4.0.0 Release – Java Binding
  • Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Recent Comments

No comments to show.

Archives

  • April 2026
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • December 2023
  • October 2023
  • August 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • May 2022
  • March 2022
  • October 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • October 2020
  • September 2020
  • August 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • May 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • January 2018

Categories

  • Getting Started
  • Uncategorized

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark