What is Git Reset and Its types
In this tutorial, we are going to learn about Git Reset and Its types.
This feature helps us to move from one commit to another and access the code present at the time of that commit.
- Hard reset
- Soft reset
- Mixed reset
Create a file with some data with multiple commits.
cat > file1 one
Send it to stagging area and commit.
git add . git commit -m "a"
Edit the same file and commit it.
cat >> file1 one two
git add . git commit -m "b"
Add some more content.
cat >> file1 one two three
git add . git commit -m "c"
If we do a hard reset head will point to the older commit and we can see the files as they were present at the time of that commit.
git reset --hard b_commitid
If we do a soft reset we will see the head point to an older commit and we can see the files present in the stagging area i.e just before the commit happend what is the status of git we will see that.
git reset --soft b_commitid
This will also move the Head to an older commit but we will see the files as they were present 2 steps before the commit took place i.e., we will see the files in the untracked/modifed section.
git reset --mixed b_commitid