Commits

What is a Commit?

A commit signals to Dolt that you would like to save the state of the current database permanently for future reference. In practice, this stores the root hash (or reference) of the database in a graph of all the commits with a link to its parent commit. If the commit is a merge commit, the commit will have multiple parents.
Commit hashes are SHA-256 encoded hashes of the entire database. Commit hashes look like t5d5inj4bpc1fltrdm9uoscjdsgebaih. These are abbreviations of the entire has that Dolt understands. When referring to a specific commit, this is the identifier you use.

How to use Commits

Dolt uses commits as the basis of comparison between two versions of a database. You can ask Dolt to do things like:
  • Show me the differences between these two commits
  • Give me the common ancestor of these two commits
  • Make my current database look like this commit
  • Show me the difference between my current database and the last commit
  • Show me all the commits since this database was created
  • Show me who created this commit and the message they left when he or she made it
You should make a commit when you want to be able to use the current version of the database to do one of the above things.
To create a commit, you tell Dolt you want to make one on the command line or in the SQL interface. A users and commit message are required. Your user is defined in configuration. You provide a commit message via the user interface.

Difference between Git Commits and Dolt commits

Git commits and Dolt commits are very similar in purpose and practice.
In Dolt, you can create a commit via the SQL interface. There is no analogue in Git.

Example

Adding a table and making a commit

CLI

1
docs $ dolt sql -q "create table docs (pk int, primary key(pk))"
2
docs $ dolt add .
3
docs $ dolt status
4
On branch main
5
Changes to be committed:
6
(use "dolt reset <table>..." to unstage)
7
new table: docs
8
docs $ dolt commit -m "Added example table docs"
9
commit 7vureh3qotrr02sog3tjgjk73sqmc2de
10
Author: Tim Sehn <[email protected]>
11
Date: Mon Dec 06 13:25:55 -0800 2021
12
13
Added example table docs
Copied!

SQL

1
docs $ dolt sql -q "create table docs_sql (pk int, primary key(pk))"
2
docs $ dolt sql -q "select dolt_commit('-a', '-m', 'Added docs_sql example table. Use -a to stage all changes for commit ie. skip dolt add')"
3
+-------------------------------------------------------------------------------------------------------------------+
4
| dolt_commit('-a', '-m', 'Added docs_sql example table. Use -a to stage all changes for commit ie. skip dolt add') |
5
+-------------------------------------------------------------------------------------------------------------------+
6
| v42og53ru3k3hak3decm23crp5p6kd2f |
7
+-------------------------------------------------------------------------------------------------------------------+
Copied!

Creating and empty commit

1
docs $ dolt commit --allow-empty -m "This is a commit"
2
commit bo318l76dq3bdvu1ie84d4nmv4hpi4km
3
Author: Tim Sehn <[email protected]>
4
Date: Thu Dec 02 16:55:00 -0800 2021
5
6
This is a commit
7
8
docs $ dolt sql -q "select dolt_commit('-a', '--allow-empty', '-m', 'This is a commit')"
9
+--------------------------------------------------------------+
10
| dolt_commit('-a', '--allow-empty', '-m', 'This is a commit') |
11
+--------------------------------------------------------------+
12
| u73s2mb1ho4mj1ldkof939vampo93bld |
13
+--------------------------------------------------------------+
Copied!
Last modified 1mo ago