What is a git commit?

If you know what a Git commit is, you will understand the physics of git. Here are some helpful ways to think about commits.
A commit is a sedimentary layer
Why does this matter? It’s most of the mental framework you need to effectively work with Git. Everything else about branches, rebasing, etc., follows from this concept.

Think of git commits as layers. Each layer is created atop its predecessor in an upward direction, with the oldest commits sifting to the bottom, and the newest at the top. Each commit represents a set of changes on top of the previous commit.

my-branch
First commit
Second commit

When you make more changes to your files, you are creating perturbations of the top layer. When you commit those changes, you are turning perturbations into a new discrete layer.

my-branch
First commit
Second commit
Third commit
Fourth commit

Other things a commit is

A commit has more qualities you should be aware of.

A commit is its commit id

Every git commit has a unique commit id. One commit is the same commit as another if and only if they both have the same commit id.

A commit is immutable

Once a git commit is created, it can never be modified. If you change any of a commit's attributes, that will spawn a new commit with the new attributes. But the old commit still exists, too (see git reflog )!

A commit is unique

A git commit is defined by the following attributes. One commit is the same commit as another if and only if the following attributes are exactly the same for both commits:

  • Commit message
  • Date the commit was created
  • The commit(s) that came immediately before it
  • The file system changes that the commit makes to the previous commit
  • Who authored the commit