Commit

Commit

A commit is a snapshot of the state of
a repository at a specific moment

A repository is thus an ordered set of commits

...and few additive stuff (we will get back to it later)
Commit

How to create a commit?

First we need to tell to git which files
we want to be included in the next commit

git add [<path_to_file>...]

Command add allows us to include files to the next snapshot(commit)

n.b. git will not include any file in a commit unless we will tell it to
Commit
git add file1.txt file2.json

What has changed?

git status
On branch master

No commits yet

Changes to be committed:
(use "git rm --cached <file>..." to unstage)
	new file:   file1.txt
	new file:   file2.json

Command status returns some information about the current repository status

Commit

What has happened?

git copied the files to the staging area

Now, the files are ready to be included in a commit

N.B. the files were copied to another place,
so if we will further edit them,
then we will have to add them again with the command git add
Commit

Let's create the commit

To do this, we use the command commit

git commit

A text file will open in our predefined text editor,
in which we have to write, in the first line,
a brief comment of the commit

We save the file and the commit will be ready

n.b. in Linux environments the default editor for git is usually `vim`, `nano` or `vi` Changing it is easy
Commit

What has happened?

git log
commit aa581d11d4caed7084cd8114d2454d9380acd869 (HEAD -> master)
Author: my_name <my_mail@poul.org>
Date:   Sat Aug 31 01:56:49 2019 +0200

This is my first commit

The command log allows us to see all the commits in the history of the repository

Commit

Can I include the comment
in the command?

git commit -m "This is my first commit"

With this syntax we will prevent the opening of
the text editor, providing the comment
through the command line

n.b. a commit's comment should not exceed 50 characters
Commit

But, what is included in a commit?

All these data will be used to create
the fingerprint (hash) of the commit

Commit

(Other) strengths

Each commit includes the fingerprint of the previous one

Edits of old commits are (generally) forbidden
and easily identifiable

Commit

But where did ctrl+z go?

Search for the fingerprint of the commit,
which we want to roll back

git reset <commit_hash>

Command reset restores the repo status to the specified old commit

Be careful: from this point you could make a mess ⚠️

n.b. it is not necessary to specify the whole fingerprint of the commit,
the initial part is sufficient