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:

  1. Getting started on GitHubCollaborate on GitHub like Pro: Part1
  2. **Branching: **Collaborate on GitHub like Pro: Part2
  3. **Commit: **Collaborate on GitHub like Pro: Commit

What is a commit?

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.

Image for post

Commit flowchart

Components of a commit:

Let us take a look into the commit object, shown below. I have highlighted the three main components in the commit, hashhead and branch (master).

Image for post

Image for post

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.

Image for post

Master branch after three commits

Switch to a specific commit

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

GitHub for Data Scientists: Commit
1.15 GEEK