How to use git reset


Hello, I’m a fresh graduate student and a newbie at Scuti Co., Ltd, after a few month working at company, I got some experience about github and git command. Today, I will share my knowledge about “How to use git reset in project”.
In my company, we using github to develop projects and with me, a newbie, the flow will like this:
  • git add <name of file or folder>
  • git commit -m “<name of commit>”
  • git pull
  • git push


  1. Git reset
I use git reset when i want to rollback my code after using git add, all my file that added will be remove .


  1. Git reset --soft
When I want to back to previous commit but dont want to remove the current changes, I will use git reset --soft <commit> to back to commit that I want and keep the current changes.
But when I dont remember name of commit, i will use git reset --soft HEAD~i with i is a number of previous commit that I want to back.


  1. Git reset --hard
git reset --hard is the command that you can remove all the changes in current status but not committed.
git reset --hard <commit> will bring you back to the commit name <commit>
git reset --hard HEAD~i, while i is a number of previous commit, will bring you back i previous commit and remove all the current changes


example:
I want to back 3 previous commit, I can use “git reset --hard HEAD~3”

If you liked this article

Let's subscribe the updates of Scuti!
Share on Google Plus

About Lợi Bùi Quang

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 Comments:

Post a Comment