Git is a veryd powerfully version control tool. Here is a summary how to make use of git checkout.
When we type
in a git repo, we will get result like this
If we want to switch to develop, we can simple checkout it.
When we check the git log, it will list commits we have made so far. For example
1 2 3 4 5
We can refer to this commit using the hash code, in addition partial of hash code, such as 20f99. Therefore we can checkout whatever commit we like using hash code.
1 2 3 4
When we checkout a commit, we are actually not in any branch.
We can give name to our commits by using git’s tag feature. We can set a tag to the current commit by using
It would be so handy if we want to go to a specific tag without checking the history. We can simply checkout this commit by using the tag name
Checkout partial files
What if we want to checkout partial files from other branches or commits? Cherry-pick would be an common option, but we can make use the checkout command. Suppose we are in master branch, and we want to bring the index.html file from develop branch. We can do this
Typing in git branch, we will find out we are still in master branch, but index.html has been updated.
Git checkout is very handy. Feel free to shoot me an Email if you know any other cool features.