避免成为垃圾邮件

by Yoel Zeldes

由Yoel Zeldes

如何避免犯垃圾 (How to avoid committing junk)

In the development process, every developer writes stuff they don’t intend to commit and push to the remote server, things like debug prints. It happens to all of us every now and then: we forget to remove this temporary stuff before committing…

在开发过程中,每个开发人员都会编写他们不打算提交并推送到远程服务器的内容,例如调试打印。 它时不时地发生在我们所有人身上:我们忘记在提交之前删除这些临时性内容…

I solved this somewhat embarrassing situation using a simple approach: to every line I don’t want to accidentally commit, I add the magic characters sequence xxx. This sequence can be in any part of the line: inside a comment, as a variable name, as a function name, you name it. A few usage examples:

我使用一种简单的方法解决了这种令人尴尬的情况:在我不想意外提交的每一行中,我添加了魔术字符序列xxx 。 该序列可以在行的任何部分:在注释内,作为变量名,函数名,您可以对其进行命名。 一些用法示例:

  • debug print: print 'xxx reached this line'.

    调试打印: print 'xxx reached this line'

  • variable used for debugging: xxx_counter = 0.

    用于调试的变量: xxx_counter = 0

  • temporary function: def xxx_print_debug_info():.

    临时功能: def xxx_print_debug_info():

  • TODO which must be attended before committing: #TODO: don't forget to refactor this function xxx.

    提交前必须要处理的TODO: #TODO: don't forget to refactor this function xxx

I implemented it using Git hooks. A hook is Git’s mechanism to fire off custom scripts when certain important actions occur. I used the pre-commit hook for validating the commit’s content.

我使用Git钩子实现了它。 挂钩是Git的机制,可在发生某些重要操作时触发自定义脚本。 我使用了pre-commit钩子来验证提交的内容。

Just create a file with the name <YOUR-REPO-FOLDER>/.git/hooks/pre-commit with the following content:

只需创建一个名称为<YOUR-REPO-FOLDER>/.git/hooks/pre- commit的文件,其内容如下:

#!/bin/sh
marks=xxx,aaamarksRegex=`echo "($marks)" | sed -r 's/,/|/g'`marksMessage=`echo "$marks" | sed -r 's/,/ or /g'`if git diff --staged | egrep -q "^\+.*$marksRegex"; then    echo "you forgot to remove a line containing $marksMessage!"    echo "you can forcefully commit using \"commit -n\""    exit 1fi
  1. marks contains the characters sequences which are not allowed to be committed.

    marks包含不允许提交的字符序列。

  2. git diff --staged shows the changes which will be committed. The changes are passed to a regular expression that searches for any forbidden mark (using egrep).

    git diff --staged显示将要提交的更改。 所做的更改将传递给正则表达式,该正则表达式搜索任何禁止的标记(使用egrep )。

  3. If a forbidden mark is found, the script exits with an error code, causing the commit to fail.如果找到了禁止标记,脚本将退出并显示错误代码,从而导致提交失败。

You want to bypass the hook? Executecommit -n. This can be useful when you want to commit a binary file such as an image, which may contain a forbidden mark.

您想绕过钩子吗? 执行commit -n 。 当您要提交二进制文件(例如图像)时,这可能很有用,例如可能包含禁止标记的图像。

Any tricks you’ve implemented in your daily git workflow? Share your magic in the comments :)

您在日常git工作流程中实施了什么技巧? 在评论中分享您的魔力:)

This post was originally posted by me at www.anotherdatum.com.

该帖子最初由我在www.anotherdatum.com上发布。

翻译自: https://www.freecodecamp.org/news/how-to-avoid-committing-junk-dae1277c1433/

避免成为垃圾邮件

避免成为垃圾邮件_如何避免犯垃圾相关推荐

  1. 什么邮件会被标记为垃圾邮件_停止将电子邮件标记为垃圾邮件的6种方法

    什么邮件会被标记为垃圾邮件 According to statista.com, 58% of all emails sent during the first months of 2017, wer ...

  2. c++ 多线程 垃圾回收器_并行并发CMS垃圾回收器:-XX:+UseConcMarkSweepGC

    概述 CMS为基于标记清除算法实现的多线程老年代垃圾回收器.CMS为响应时间优先的垃圾回收器,适合于应用服务器,如网络游戏,电商等和电信领域的应用. 为了实现这个目的,与其他垃圾回收器不同的是,CMS ...

  3. java不同垃圾回收器_细述 Java垃圾回收机制→Types of Java Garbage Collectors

    本文非原创,翻译自Types of Java Garbage Collectors 在Java中为对象分配和释放内存空间都是由垃圾回收线程自动执行完成的.和C语言不一样的是Java程序员不需要手动写垃 ...

  4. 编程基础 垃圾回收_编程中的垃圾回收指南

    编程基础 垃圾回收 什么是垃圾回收? (What is Garbage Collection?) In general layman's terms, Garbage collection (GC) ...

  5. java final 垃圾回收_新的Java垃圾回收机制ZGC 简介

    垃圾回收是Java的一项重要机制,是二月份的一项学习计划之一. ZGC是一种较新的垃圾回收机制,在JDK11中实验性引入,看了R大的几篇文章,依然不懂,之后发现了一篇介绍地比较易懂的文章: 希望对你有 ...

  6. 垃圾邮件分类 python_在python中创建SMS垃圾邮件分类器

    垃圾邮件分类 python 介绍 (Introduction) I have always been fascinated with Google's gmail spam detection sys ...

  7. 吴恩达|机器学习作业6.1.SVM建立垃圾邮件分类器

    6.1.SVM建立垃圾邮件分类器 1)题目: 如今,许多电子邮件服务提供垃圾邮件过滤器,能够将电子邮件精确地分类为垃圾邮件和非垃圾邮件.在本部分练习中,您将使用SVM构建自己的垃圾邮件过滤器. 您将训 ...

  8. 朴素贝叶斯(西瓜数据集分类,社区恶意留言分类,垃圾邮件分类,新浪新闻分类),AODE分类器 代码实现

    朴素贝叶斯(西瓜数据集分类,社区恶意留言分类,垃圾邮件分类,新浪新闻分类),AODE分类器 代码实现 以下代码为本人学习后,修改或补充后的代码实现,数据集和原代码请参考:https://github. ...

  9. 垃圾邮件攻击与勒索病毒家族VoidCrypt

    第一部分 垃圾邮件 <中国互联网协会反垃圾邮件规范>是这样定义垃圾邮件特征的: 收件人事先没有提出要求或者同意接收的广告或推广宣传性质的电子邮件: 收件人无法拒收的电子邮件: 隐藏发件人身 ...

最新文章

  1. css 中文字旋转,css
  2. 刨根问底:C++中宽字符类型(wchar_t)的编码一定是Unicode?长度一定是16位?
  3. 显示浏览器窗口的高度和宽度
  4. 细说SSO单点登录(转)
  5. spring boot 整合redis实现方法缓存
  6. union all怎么用在循环里_ai软件怎么使用?ai里基本功能怎么用?
  7. 2021牛客OI赛前集训营-提高组(第五场)D-牛牛的border【SAM】
  8. linux 循环执行ip停止服务,java调用远程服务器的shell脚本以及停止的方法实现
  9. 【面试题22】栈的压入、弹出序列
  10. [转载] Java中的abstract关键字
  11. IDEA插件系列-玩转JSON与实体类互相转换
  12. LINUX内核段错误调试详细指南精品培训PPT讲义
  13. uni-app如何发送请求调用接口
  14. iOS之加载Gif图片
  15. 微信小程序前台开发——实现登录,底部导航栏,顶部导航栏(分类显示)
  16. ACM ICPC 2008–2009 NEERC MSC A, B, C, G, L
  17. 元旦贺卡html,元旦新年贺卡怎么做
  18. android studio 使用lint工具优化app时全过程记录
  19. 皮皮虾技术三面,我的面试经验与总结分享
  20. 最新获得淘宝app商品详情原数据 的API

热门文章

  1. oracle导入索引b报错,impdp导入索引很慢
  2. iOS中你可能没有完全弄清楚的(二)自己实现一个KVO源码及解析
  3. JS中8个常见的陷阱
  4. 洛谷P3723 [AH2017/HNOI2017]礼物(FFT)
  5. ubuntu安装deepin terminal 终端
  6. 用Cordova打包Vue-vux项目
  7. 表格中td限宽溢出以省略号代替
  8. consul安装配置使用
  9. 视音频数据处理入门:RGB、YUV像素数据处理【转】
  10. string与数值之间的转换