{"thread":{"id":"21695","subject":"How to make git diff-* ignore some patterns?","startedAt":"2009-11-21T16:40:14Z","lastAt":"2009-11-22T15:51:49Z","messageCount":4,"participants":["Dirk Süsserott","Björn Steinbrink","Michael J Gruber"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"128068","messageId":"4B0817EE.1040000@dirk.my1.cc","threadId":"21695","inReplyTo":null,"subject":"How to make git diff-* ignore some patterns?","fromName":"Dirk Süsserott","fromEmail":"newsletter@dirk.my1.cc","sentAt":"2009-11-21T16:40:14Z","receivedAt":"2009-11-21T16:40:14Z","isPatch":false,"sender":{"key":"newsletter@dirk.my1.cc","avatar":null},"body":"Hi list,\n\nis there a way to tell \"git diff-index\" to ignore some special patterns, \nsuch that /^-- Dump completed on .*$/ is NOT recognized as a difference \nand \"git diff-index\" returns 0 if that's the only difference?\n\n     -- Dirk\n\n<Background>\nI have a mySQL database which I backup daily using mysqldump (cronjob).\nThe result is a text file (*.sql) with all the \"create\" and \"insert\"\nstatements and some metadata.\nI used to use tar and gzip to backup these files and got a huge\ncollection of backups in the last tree years (500+ MB).\nThen I switched to Git and recorded only the diffs between day X and day\nX-1. My repository shrunk to 16 MB for the very same data, which was great!\n\nMy database doesn't change every day, but I backup it anway and store \nthe backup files with Git and a cronjob. It does:\n\n---------------\nmysqldump ... -r <backupfile> # that's the output file ;-)\ngit add <backupfile>\nif ! git diff-index --quiet HEAD --; then\n     git commit -m \"Backup of <database> at <timestamp>\"\nfi\n---------------\n\nThis way, a new commit is only done when the backupfile has changed. So \nfar, so perfect.\nA few days ago my web hoster (where the database actually resides) \nchanged the mySQL version.\nmysqldump now writes \"-- Dump completed on <timestamp>\" to the file and \nGit correctly recognizes this as a change and my script creates a new \ncommit. Every day, even if only that line has changed.\n\nI'd like to skip these commits if only the \"Dump completed\" line has \nchanged.\n</Background>\n"},{"id":"128078","messageId":"4B0823F7.7030607@drmicha.warpmail.net","threadId":"21695","inReplyTo":"4B0817EE.1040000@dirk.my1.cc","subject":"Re: How to make git diff-* ignore some patterns?","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2009-11-21T17:31:35Z","receivedAt":"2009-11-21T17:31:35Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Dirk Süsserott venit, vidit, dixit 21.11.2009 17:40:\n> Hi list,\n> \n> is there a way to tell \"git diff-index\" to ignore some special patterns, \n> such that /^-- Dump completed on .*$/ is NOT recognized as a difference \n> and \"git diff-index\" returns 0 if that's the only difference?\n> \n>      -- Dirk\n> \n> <Background>\n> I have a mySQL database which I backup daily using mysqldump (cronjob).\n> The result is a text file (*.sql) with all the \"create\" and \"insert\"\n> statements and some metadata.\n> I used to use tar and gzip to backup these files and got a huge\n> collection of backups in the last tree years (500+ MB).\n> Then I switched to Git and recorded only the diffs between day X and day\n> X-1. My repository shrunk to 16 MB for the very same data, which was great!\n> \n> My database doesn't change every day, but I backup it anway and store \n> the backup files with Git and a cronjob. It does:\n> \n> ---------------\n> mysqldump ... -r <backupfile> # that's the output file ;-)\n> git add <backupfile>\n> if ! git diff-index --quiet HEAD --; then\n>      git commit -m \"Backup of <database> at <timestamp>\"\n> fi\n> ---------------\n> \n> This way, a new commit is only done when the backupfile has changed. So \n> far, so perfect.\n> A few days ago my web hoster (where the database actually resides) \n> changed the mySQL version.\n> mysqldump now writes \"-- Dump completed on <timestamp>\" to the file and \n> Git correctly recognizes this as a change and my script creates a new \n> commit. Every day, even if only that line has changed.\n> \n> I'd like to skip these commits if only the \"Dump completed\" line has \n> changed.\n> </Background>\n\nIs the dump guaranteed to be in a specific order? If yes then this\nprocedure makes sense. (pdfs etc. are problematic because of reordering.)\n\nYou can either egrep -v through the output of git diff-index, or define\na diff driver: set an attribute, say \"dumpdiff\", for dump files (see\ngitattributes) and define diff driver as\ngit config diff.dumpdiff.textconv = dumpdiff.sh\nwhere dumpdiff.sh is \"egrep -v ...\". You may need to call diff-index\nwith --ext-diff. I haven't tried, though ;)\n\nCheers,\nMichael\n"},{"id":"128075","messageId":"20091121180738.GA14919@atjola.homenet","threadId":"21695","inReplyTo":"4B0817EE.1040000@dirk.my1.cc","subject":"Re: How to make git diff-* ignore some patterns?","fromName":"Björn Steinbrink","fromEmail":"b.steinbrink@gmx.de","sentAt":"2009-11-21T18:07:38Z","receivedAt":"2009-11-21T18:07:38Z","isPatch":false,"sender":{"key":"b.steinbrink@gmx.de","avatar":"https://avatars.githubusercontent.com/u/230962?v=4"},"body":"On 2009.11.21 17:40:14 +0100, Dirk Süsserott wrote:\n> is there a way to tell \"git diff-index\" to ignore some special\n> patterns, such that /^-- Dump completed on .*$/ is NOT recognized as\n> a difference and \"git diff-index\" returns 0 if that's the only\n> difference?\n\nIf you don't mind losing that line, you could use a clean filter via\n.gitattributes:\n\necho '*.sql filter=mysql_dump' >> .gitattributes\ngit config filter.mysql_dump.clean \"sed -e '/^-- Dump completed on .*$/d'\"\n\nThat way, git will filter all *.sql paths through that sed command\nbefore storing them as blobs, dropping that \"Dump completed\" line from\nthe data stored in the repo.\n\nBjörn\n"},{"id":"128104","messageId":"4B095E15.9040209@dirk.my1.cc","threadId":"21695","inReplyTo":"20091121180738.GA14919@atjola.homenet","subject":"Re: How to make git diff-* ignore some patterns?","fromName":"Dirk Süsserott","fromEmail":"newsletter@dirk.my1.cc","sentAt":"2009-11-22T15:51:49Z","receivedAt":"2009-11-22T15:51:49Z","isPatch":false,"sender":{"key":"newsletter@dirk.my1.cc","avatar":null},"body":"Am 21.11.2009 19:07 schrieb Björn Steinbrink:\n> On 2009.11.21 17:40:14 +0100, Dirk Süsserott wrote:\n>> is there a way to tell \"git diff-index\" to ignore some special\n>> patterns, such that /^-- Dump completed on .*$/ is NOT recognized as\n>> a difference and \"git diff-index\" returns 0 if that's the only\n>> difference?\n> \n> If you don't mind losing that line, you could use a clean filter via\n> .gitattributes:\n> \n> echo '*.sql filter=mysql_dump' >> .gitattributes\n> git config filter.mysql_dump.clean \"sed -e '/^-- Dump completed on .*$/d'\"\n> \n> That way, git will filter all *.sql paths through that sed command\n> before storing them as blobs, dropping that \"Dump completed\" line from\n> the data stored in the repo.\n> \n> Björn\n> \n\nThank you Björn and Michael,\n\nYour suggestions were really helpful. I decided to use Björn's 'clean\nfilter' approach. It works great.\n\n-- Dirk\n"}]}