I am Mikhail Evdokimov, a Hobbyist Self Taught Programmer
Git Tips and Tricks
March
16th,
2016
This article is for all those who want to know about how to work with Git as well as learn more than a list of simple commands
such as git init, git add, git commit and git push.
I note that this article is subject to change from time to time and/or updated with new Tips and Tricks about working with Git.
So, let’s begin with a simple
Suppose that you’ve committed but you do not like the content or you have made any bug or
you are for any other reason wish undoing or reset recent changes in your repository.
For these situations Git provided powerful command git reset
git reset HEAD
You make some changes in your file and run git add file.ext command
but forgot to do something, and not yet ready to commit to do and want to return to modified state.
Just run command git reset HEAD
and make changes.
git reset HEAD~n soft and hard
Sometimes there are situations when you create a lot of commits with small changes which then can be placed under a single commit,
thereby reducing the number of commits in your repository.
To do this, you can first run the command git log --oneline
to make sure the number of commits that you would like to make a reset.
Then just run the command git reset --soft HEAD~n where n is number of last commits for reset.
--soft key moves branch to HEAD~n and stopped at this place. Without making changes to files.
Now you can create a new commit and then run the command git log --oneline
to see what happened.
In addition --soft key, git reset have key --hard
which moves branch to HEAD~n with hard reset all changes in repository to the specified n.