git/list[1] front-page[2] threads[3] people[4] search[5] about
 

How to make git diff-* ignore some patterns?

From
DSDirk Süsserott <newsletter@dirk.my1.cc>
Date
Nov 21, 2009, 16:40 UTC
Message-ID
<4B0817EE.1040000@dirk.my1.cc>
Hi list,

is there a way to tell "git diff-index" to ignore some special patterns, such that /^-- Dump completed on .*$/ is NOT recognized as a difference and "git diff-index" returns 0 if that's the only difference?

     -- Dirk

<Background> I have a mySQL database which I backup daily using mysqldump (cronjob). The result is a text file (*.sql) with all the "create" and "insert" statements and some metadata. I used to use tar and gzip to backup these files and got a huge collection of backups in the last tree years (500+ MB). Then I switched to Git and recorded only the diffs between day X and day X-1. My repository shrunk to 16 MB for the very same data, which was great!

My database doesn't change every day, but I backup it anway and store the backup files with Git and a cronjob. It does:

---------------
mysqldump ... -r <backupfile> # that's the output file ;-)
git add <backupfile>
if ! git diff-index --quiet HEAD --; then
     git commit -m "Backup of <database> at <timestamp>"
fi
---------------

This way, a new commit is only done when the backupfile has changed. So far, so perfect. A few days ago my web hoster (where the database actually resides) changed the mySQL version. mysqldump now writes "-- Dump completed on <timestamp>" to the file and Git correctly recognizes this as a change and my script creates a new commit. Every day, even if only that line has changed.

I'd like to skip these commits if only the "Dump completed" line has changed. </Background>

Next: Michael J Gruber
Message 1 of 4 in “How to make git diff-* ignore some patterns?”
  1. Dirk SüsserottNov 21, 2009
  2. Michael J GruberNov 21, 2009
  3. Björn SteinbrinkNov 21, 2009
  4. Dirk SüsserottNov 22, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.