This article is part of a follow-along series on GitHub collaboration. In this article, we will try to understand commits in detail, like components of a commit, how to delete commit before and after push or how to reset it.
If you are a beginner and want to understand the practical application, I will recommend a quick read into the article, Collaborate on GitHub like Pro: **Part1 **before you start with this article.
The series, Collaborate on GitHub like pro, focus on specific topics:
Commits are created with the git commit command to capture the state of a project at that point in time. When you make a commit, Git stores a commit object that contains a pointer to the snapshot of the content you staged (indexed), please see below commit stage highlighted in red box.
Commit flowchart
Let us take a look into the commit object, shown below. I have highlighted the three main components in the commit, hash, head and branch (master).
Commit Object
Hash: Every commit creates unique hash for the respective commits. These hashes can later be used to revert to that version or find details on the commit. Usually, only the first 7 characters are used to look for respective commit.
Head: Shows which branch you are working on currently. In the above image, head is pointing to master, which means currently you are working on the master branch.
**Branch: **By default, the first line of development (branch) is named as master. All the preceding work on different branches gets merged to master.
To understand this concept further refer to this blog post.
Master branch after three commits
There are multiple ways to checkout to a specific commit based on the use cases. You might want to make a temporary or permanent switch. Sometimes you might want to go a few steps back and maybe add a feature from that step onwards.
#commit-git #git-revert-commit #checkout-git #show-heads #git-delete-branch