Skip to main content

USING RESET IN GIT



 Case1:

First initialize git
#git init
Now clone with our repo git-test
#git clone git@github.com:arunm8489/git-test.git
#cd git-test
#ls
This will list the files present in our repository.Now create a new file test4 and add it to index(staging)

We can see test4 is staged.Here comes one of the use of reset.
#git reset HEAD test4
This will moves the test4 from staging to working area.To see it
#git status

Here what happened is file is moved from staging to working area

Case2:

Here we can test what git reset --hard HEAD will do.create another file test5 and add both test4 and test5 to staging.
#git add test4 test5
# git reset --hard HEAD
We can see that  all changes we made will be gone and entire content in repository will be reflected in working area.


Case 3:

Now we will check another use of reset
Create file test4 and test5
Add it to staging and commit it

Now check commits by using
#git log
Suppose if we want to go back to condition before we add test4 and test5 we want to notice the hash value of commit(9df603f)  and by using git reset we can revert back
#git reset --hard 9df60d3f
We can examine the new commit by using git log command