# Tracking changes

When you check out a Splitgraph image into a schema, sgr enables change tracking via PostgreSQL audit triggers. When any application writes to that schema, the audit triggers will capture the changes, allowing sgr to package them into new images as a set of delta-compressed patches. This way, keeping track of table history is space efficient.

You can view changes to the current working checkout or between any two images in a repository with the sgr diff command.

You can view the history of all changes to an image with the sgr log command. This shows just the history following the parent chain of an image. Passing -t will make sgr render the history of the whole repository as a tree.

## Example

Let's create another example repository and give the new image a tag:

$sgr example generate example/repo_2$ sgr sql --schema example/repo_2 "SELECT * FROM demo ORDER BY key"
$sgr tag example/repo_2 original_data  You can do the next step using any SQL client that can access the PostgreSQL database backing the sgr engine, but sgr provides a shorthand to alter the generated image: $ sgr example alter example/repo_2

Deleting 2 rows...
Updating 2 rows...


Let's inspect the current state of the repository:

$sgr sql --schema example/repo_2 "SELECT * FROM demo ORDER BY key"  You should see that the first two rows are now missing, the second two rows have been altered and two more rows have been added. Let's compare the demo table to its previous version: $ sgr diff example/repo_2 -v

Between 97900a827962 and the current working copy:
demo: added 4 rows, removed 4 rows.
- (0, '5feceb66ffc86f38d952786c6d696c79c2dbc239dd4e91b46729d73a27fb57e9')