# Commits

## What is a Commit?

A commit signals to Doltgres 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.

![](/files/2Zh73i0SFRa8ShrArmov)

Commit hashes are SHA-256 encoded hashes of the entire database. Commit hashes look like`t5d5inj4bpc1fltrdm9uoscjdsgebaih`. These are abbreviations of the entire hash that Doltgres\
understands. When referring to a specific commit, this is the identifier you use.

A Doltgres commit is different from a standard SQL transaction commit. Doltgres supports both which\
can be a bit confusing.

## How to use Commits

Doltgres uses commits as the basis of comparison between two versions of a database. You can ask\
Doltgres 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 call the `DOLT_COMMIT()` function. A user 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 Doltgres commits

Git commits and Doltgres commits are very similar in purpose and practice.

## Example

```sql
create table docs_sql (pk int, primary key(pk));
select dolt_commit('-a', '-m', 'Added docs_sql example table. Use -a to stage all changes for commit ie. skip dolt add');
+-------------------------------------------------------------------------------------------------------------------+
| dolt_commit('-a', '-m', 'Added docs_sql example table. Use -a to stage all changes for commit ie. skip dolt add') |
+-------------------------------------------------------------------------------------------------------------------+
| v42og53ru3k3hak3decm23crp5p6kd2f                                                                                  |
+-------------------------------------------------------------------------------------------------------------------+
```

### Creating an empty commit

```sql
select dolt_commit('--allow-empty', '-m', 'This is a commit');
+--------------------------------------------------------------+
| dolt_commit('-a', '--allow-empty', '-m', 'This is a commit') |
+--------------------------------------------------------------+
| u73s2mb1ho4mj1ldkof939vampo93bld                             |
+--------------------------------------------------------------+
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.doltgres.com/concepts/git/commits.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
