git可以忽略匹配模式的特定行吗? [英] Can git ignore specific lines matching a pattern?

查看:79
本文介绍了git可以忽略匹配模式的特定行吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



使用--skip-extended-insert,所以每条记录都在它自己的行上,它的工作原理相当稳定以及跟踪变化。它还允许我从历史记录中提取旧版本的数据库并导入它们。



有没有办法告诉git忽略某些包含特定模式的行或行? / b>

解决方案



Git是基于文件的,它不会修改跟踪文件的内容来派生diffs。

可能的选择



删除cruft



不要在您不关心的数据库转储中包含表/数据。如果没有创建差异,则不需要采取额外的步骤来忽略/更正它。



因此,例如,问题是删除了您的文章不希望备份,从备份过程中删除它们:

  mysqldump -c -warticles.deleted IS NULL文章> backup.sql 



后期处理



发布处理数据库转储以删除您不关心的内容。作为一个例子,下面是我使用的数据库转储帮助器脚本的摘录:

 #!/ 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

此示例(仅用于说明)从create table语句中删除自动增量值,以便它们不会在(版本控制的)schema.sql文件中生成差异。


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?

解决方案

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.

这篇关于git可以忽略匹配模式的特定行吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆