Git hook for diff sqlite table

Here is how to use git's textconv feature for showing diffs between versions of the sqlite file. It just does a dump, so it may not be super efficient for large databases. No hook necessary.

That link seems to be no longer available, so I'm using the the archived version instead.

The gist of it is, in the git attributes file (.gitattributes, or .git/info/attributes), add a pattern match to force sqlite3 diffs (assuming your database files have the extension .sqlite3):

*.sqlite3 diff=sqlite3

Then in your git config file (~/.gitconfig or .git/config):

[diff "sqlite3"]
    binary = true
    textconv = "echo .dump | sqlite3"

If you just want to track schema changes, use .schema instead of .dump.


You would use HEAD and HEAD^ to access the previous and current revisions; see git post-commit hook - script on committed files for an example.

Use git show to extract files to a temporary directory without overwriting the working copy.


I wouldn't store binary files in git unless absolutely necessary. You can avoid many hassles if you create a text file of SQL commands with sqlite3 file.sqlite .dump and put that into git, having the binary database only as a generated file. (But then you have to care about regenerating the SQL file when necessary.)