Doltgres Cheat Sheet#

This cheat sheet briefly summarizes the main version-control features of Doltgres with simple examples.

Click links in the comments section to read docs for the feature.

Setup and init#

SQLComments
CREATE DATABASE mydb;Creates a new Doltgres database
SELECT DOLT_CLONE('post-no-preference/options');Clones the post-no-preference/options database from DoltHub

Stage and snapshot#

SQLComments
SELECT DOLT_ADD('myTable');Adds a table to the staging area
SELECT DOLT_RESET();Removes staged tables, keeps working changes
SELECT DOLT_RESET('--hard');Resets all staged and working changes to HEAD
SELECT DOLT_COMMIT('-m', 'a commit');Commits staged tables as a new snapshot
SELECT DOLT_COMMIT('-Am', 'a commit');Stages and commits all tables

Branch and merge#

SQLComments
SELECT * FROM dolt_branches;Lists all branches
SELECT DOLT_BRANCH('myBranch');Creates a new branch
SELECT DOLT_CHECKOUT('myBranch');Switches to another branch
SELECT DOLT_CHECKOUT('-b', 'myBranch');Creates a new branch and switches to it
SELECT DOLT_MERGE('myBranch');Merges a branch into the checked out branch

Diffing#

SQLComments
SELECT * FROM dolt_diff('HEAD', 'WORKING', 'mytable');Shows the working diff for mytable
SELECT * FROM dolt_diff_stat('HEAD', 'WORKING', 'mytable');Shows statistics for the diff of mytable
SELECT * FROM dolt_diff('HEAD~', 'HEAD', 'mytable');Shows the diff between the last two commits for mytable
SELECT * FROM dolt_diff('HEAD', 'STAGED', 'mytable');Shows the staged diff for mytable
SELECT * FROM dolt_diff('branchA', 'branchB', 'mytable');Shows diff between branches two branches for mytable

Status and logs#

SQLComments
SELECT * FROM dolt_status;Shows which tables are modified or staged
SELECT active_branch();Shows the checked out branch
SELECT * FROM dolt_log;Shows the commit history for the current branch
SELECT * FROM dolt_log('myBranch');Shows the commit history for myBranch
SELECT * FROM dolt_log('branchB..branchA');Shows the commits on branchA that are not on branchB

History#

SQLComments
SELECT * FROM mytable AS OF 'HEAD~3';Selects data from 3 commits ago
USE mydb/HEAD~3;Sets this session to query data from 3 commits ago
SELECT * FROM dolt_history_mytable;Selects every row from mytable at every point in history
SELECT committer FROM dolt_history_mytable where id = 1 order by commit_date LIMIT 1;Selects who first added the row with id = 1 to mytable

Working with remotes#

SQLComments
SELECT DOLT_REMOTE('add', 'myRemote', 'myOrg/myRepo');Adds a new DoltHub remote
SELECT * FROM dolt_remotes;Lists remotes
SELECT DOLT_FETCH();Fetches all branches from the remote
SELECT DOLT_PULL();Fetch and merge commits from the remote tracking branch
SELECT DOLT_PUSH('origin', 'myBranch');Push local commits of branch myBranch to remote origin
SELECT DOLT_PUSH();Push local commits to the remote tracking branch

Advanced use cases#

SQLComments
SELECT HASHOF('main');Shows the commit hash of a ref
SELECT * from dolt_blame_mytable;Shows who last updated every row of a table
SELECT * FROM dolt_diff('branch1...branch2');Shows a three-dot diff
SELECT DOLT_REVERT('gtfv1qhr5le61njimcbses9oom0de41e');Creates a new commit which reverts the changes in a prior commit
SELECT * FROM DOLT_PATCH('main', 'WORKING');Creates SQL statements to apply a diff between two revisions
SELECT * FROM dolt_conflicts;Lists which tables have conflicts after a merge
SELECT * FROM [dolt_conflicts_mytable];Lists the rows in conflict for mytable
SELECT DOLT_CONFLICTS_RESOLVE('--theirs', 'mytable');Resolves conflicts in mytable by taking their changes
SELECT DOLT_TAG('tag1', 'myBranch');Creates a new tag at the HEAD of mybranch
SELECT DOLT_CHERRY_PICK('qj6ouhjvtrnp1rgbvajaohmthoru2772');Applies the changes in a commit to the current branch HEAD
SELECT * FROM dolt_schema_diff('main', 'branch1', 'mytable');Shows schema differences for a table between two commits
SELECT DOLT_VERIFY_CONSTRAINTS();Checks for constraint violations (e.g. after checks had been disabled)
SELECT DOLT_GC();Runs garbage collection to compact the size of the database on disk
SELECT DOLT_REBASE('--interactive', 'main');Begins an interactive rebase session
SELECT * FROM dolt_reflog('mybranch');Shows the history of a ref, included deleted refs
SELECT * FROM dolt_commit_ancestors where commit_hash = HASHOF('main');Shows the parent commit(s) of a commit
SELECT DOLT_MERGE_BASE('main', 'feature');Shows the common ancestor of two commits
SELECT * FROM dolt_commits;Shows all commits on all branches
INSERT INTO dolt_ignore VALUES ('generated_*', true);Ignores tables matching generated* (won’t be added or committed)