9

I version control mysql database dumps from websites with git.

With --skip-extended-insert, so each record is on it's own line, it works quite well to track changes. It also allows me to pull old versions of the database from history and import them.

Is there a way to tell git to ignore certain lines or lines containing certain patterns?

1
  • It may now be possible where it was not before. Is this question answered here? "ignoring changes matching a string in git diff" stackoverflow.com/questions/15878622/… Commented Jan 19, 2022 at 22:37

2 Answers 2

8

No

Git is file based, it will not modify the contents of tracked files to derive diffs.

Possible alternatives

Remove cruft

Don't include tables/data in the db dumps that you don't care for. If it's not there creating differences, you don't need to take extra steps to ignore/correct for it.

So if for example, the problem is deleted articles that you don't want to backup, remove them from the backup process:

mysqldump -c -w "articles.deleted IS NULL" articles > backup.sql 

Post process

Post process the database dump to remove things you don't care for. As an example, here's an extract from a db dump helper script I use:

#!/bin/bash mysqldump -dRC --skip-dump-date --skip-add-drop-table --default-character-set=utf8 database $@ > schema.sql sed -i 's/ AUTO_INCREMENT=[0-9]\+//' schema.sql 

This example (for illustration only) removes autoincrement values from create table statements so that they don't generate differences in the (version controlled) schema.sql file.

Sign up to request clarification or add additional context in comments.

Comments

1

If git cannot do this, the two solutions I see are:

  1. Modify the script I use to dump the database to remove things that are irrelevant to version control. (drawback: removing some of these things might cause the dump to no longer be viable for import)

  2. Store each database dump somewhere else (maybe named by commitID somehow within a hook) and version control a modified version. e.g.,cat dump.sql | grep -v "_session" >> dump.sql, but it would be ideal if I could add a grep like this to git somewhere.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.