Dolt Cheat Sheet#

This cheat sheet briefly summarizes the main version-control features of Dolt with simple examples. Most commands can be executed on the command line or in a SQL session. Most Dolt commands take the same options as Git commands.

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

Setup and init#

SQL serverDolt CLIComments
CREATE DATABASE mydb;dolt initCreates a new Dolt database
CALL DOLT_CLONE('post-no-preference/options');dolt clone post-no-preference/optionsClones the post-no-preference/options database from DoltHub

Stage and snapshot#

SQL serverDolt CLIComments
CALL DOLT_ADD('myTable');dolt add myTableAdds a table to the staging area
CALL DOLT_RESET();dolt resetRemoves staged tables, keeps working changes
CALL DOLT_RESET('--hard');dolt reset --hardResets all staged and working changes to HEAD
CALL DOLT_COMMIT('-m', 'a commit');dolt commit -m 'a commit'Commits staged tables as a new snapshot
CALL DOLT_COMMIT('-Am', 'a commit');dolt commit -Am 'a commit'Stages and commits all tables

Branch and merge#

SQL serverDolt CLIComments
SELECT * FROM dolt_branches;dolt branchLists all branches
CALL DOLT_BRANCH('myBranch');dolt branch myBranchCreates a new branch
CALL DOLT_CHECKOUT('myBranch');dolt checkout myBranchSwitches to another branch
CALL DOLT_CHECKOUT('-b', 'myBranch');dolt checkout -b myBranchCreates a new branch and switches to it
CALL DOLT_MERGE('myBranch');dolt merge mybranchMerges a branch into the checked out branch

Diffing#

SQL serverDolt CLIComments
SELECT * FROM dolt_diff('HEAD', 'WORKING', 'mytable');dolt diff mytableShows the working diff for mytable
SELECT * FROM dolt_diff_stat('HEAD', 'WORKING', 'mytable');dolt diff --stat mytableShows statistics for the diff of mytable
SELECT * FROM dolt_diff('HEAD~', 'HEAD', 'mytable');dolt diff HEAD~ HEAD mytableShows the diff between the last two commits for mytable
SELECT * FROM dolt_diff('HEAD', 'STAGED', 'mytable');dolt diff --cached mytableShows the staged diff for mytable
SELECT * FROM dolt_diff('branchA', 'branchB', 'mytable');dolt diff branchA branchB mytableShows diff between branches two branches for mytable

Status and logs#

SQL serverDolt CLIComments
SELECT * FROM dolt_status;dolt statusShows which tables are modified or staged
SELECT active_branch();dolt branchShows the checked out branch (marked with * on CLI)
SELECT * FROM dolt_log;dolt logShows the commit history for the current branch
SELECT * FROM dolt_log('myBranch');dolt log myBranchShows the commit history for myBranch
SELECT * FROM dolt_log('branchB..branchA');dolt log branchB..branchAShows the commits on branchA that are not on branchB

History#

History querying is specific to the SQL server and has no command line equivalent.

SQL serverComments
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#

SQL serverDolt CLIComments
CALL DOLT_REMOTE('add', 'myRemote', 'myOrg/myRepo');dolt remote add myRemote/myRepoAdds a new DoltHub remote
SELECT * FROM dolt_remotes;dolt remoteLists remotes
CALL DOLT_FETCH();dolt fetchFetches all branches from the remote
CALL DOLT_PULL();dolt pullFetch and merge commits from the remote tracking branch
CALL DOLT_PUSH('origin', 'myBranch');dolt push origin myBranchPush local commits of branch myBranch to remote origin
CALL DOLT_PUSH();dolt pushPush local commits to the remote tracking branch

Advanced use cases#

SQL serverDolt CLIComments
SELECT HASHOF('main');dolt show mainShows the commit hash of a ref
SELECT * from dolt_blame_mytable;dolt blame mytableShows who last updated every row of a table
SELECT * FROM dolt_diff('branch1...branch2');dolt diff branch1...branch2Shows a three-dot diff
CALL DOLT_REVERT('gtfv1qhr5le61njimcbses9oom0de41e');dolt revert gtfv1qhr5le61njimcbses9oom0de41eCreates a new commit which reverts the changes in a prior commit
SELECT * FROM DOLT_PATCH('main', 'WORKING');dolt patch mainCreates SQL statements to apply a diff between two revisions
SELECT * FROM dolt_conflicts;dolt conflicts catLists which tables have conflicts after a merge
SELECT * FROM [dolt_conflicts_mytable];dolt conflicts cat mytableLists the rows in conflict for mytable
CALL DOLT_CONFLICTS_RESOLVE('--theirs', 'mytable');dolt conflicts resolve --theirs mytableResolves conflicts in mytable by taking their changes
CALL DOLT_TAG('tag1', 'myBranch');dolt tag tag1 mybranchCreates a new tag at the HEAD of mybranch
CALL DOLT_CHERRY_PICK('qj6ouhjvtrnp1rgbvajaohmthoru2772');dolt cherry-pick qj6ouhjvtrnp1rgbvajaohmthoru2772Applies the changes in a commit to the current branch HEAD
SELECT * FROM dolt_schema_diff('main', 'branch1', 'mytable');dolt diff --schema main branch1 Shows schema differences for a table between two commits
CALL DOLT_VERIFY_CONSTRAINTS();dolt verify-constraintsChecks for constraint violations (e.g. after checks had been disabled)
CALL DOLT_GC();dolt gcRuns garbage collection to compact the size of the database on disk
CALL DOLT_REBASE('--interactive', 'main');dolt rebase --interactive mainBegins an interactive rebase session
SELECT * FROM dolt_reflog('mybranch');dolt reflog mybranchShows the history of a ref, included deleted refs
SELECT * FROM dolt_commit_ancestors where commit_hash = HASHOF('main');No equivalentShows the parent commit(s) of a commit
SELECT DOLT_MERGE_BASE('main', 'feature');dolt merge-base main featureShows the common ancestor of two commits
SELECT * FROM dolt_commits;No equivalentShows all commits on all branches
INSERT INTO dolt_ignore VALUES ("generated_*", true);No equivalentIgnores tables matching generated* (won’t be added or committed)