Git question | What is a commit?

Screen Link:

My question:
On a former screen it was explained that a commit represents the changes from the latest commited version to the current status. On the last picture of the screen, it looks like a commit is always representing the complete current version.

Can you please explain what of the two a commit is: (1) the difference between the latest commit and the current status or (2) a complete picture of the current status?

Best
Binchentso

Hi Binchentso! It’s a great question.

A commit is an operation which sends the latest changes of the source code to the repository, making these changes part of the head revision of the repository. Commit represents the entire state. However, it contains more than just state: it also has a pointer to a parent commit (typically one, but can be any number), such as the previous commit in the repository’s history. The parent pointer lets git figure out the differences between the current commit and its parent. This is what cherry-pick does: it computes the diff, then applies just those differences to the current state.

1 Like

Hi @gorelovaelizaveta01 and thanks for your answer. From your comment it sounds like a commit is always the complete picture and that with the pointer git can find out the differences between the two commits. I hope I got that right?

What are you referring to when you say “Commit represents the entire state.”?