草莓干 发表于 2020-12-10 16:47:12

Git Cz , Fuzzy 让你飞起来

<p><br/></p><section style="border-bottom: 1px solid #ddd;margin: 0 auto 10px;"><p class="135brush" data-brushtype="text" style="padding: 0px 5px 6px; border-bottom-width: 2px; border-bottom-style: solid; border-bottom-color: rgb(239, 112, 96); display: inline-block; margin: 0px 0px -1px; font-weight: normal; line-height: 1.1; font-size: 18px;"><span style="font-size: 16px;"><strong><span style="font-family: 微软雅黑, Microsoft YaHei;">Git是什么?</span></strong></span></p></section><p style="line-height: 1.75em; margin-bottom: 10px;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">https://git-scm.com/docs</span></p><p style="line-height: 1.75em; margin-bottom: 10px;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">如果你是一个程序员,那么你每天接触最多的应该是源代码。如何合理的管理好源代码,这个是作为程序员的立身之本。而 git 就是作为一个优秀的源代码管理工具而设计的,在世界上最大,最复杂,最活跃的 linux kernel 项目中被使用。同时这个工具也是作为辅助 linux kernel 开发而设计的。</span></p><p style="line-height: 1.75em; margin-bottom: 10px;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">Git 能帮你解决你最关心的问题: 我刚才都修改了什么?它把每一次的修改作为一个 commit 记录下来。</span></p><p style="line-height: 1.75em; margin-bottom: 10px;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">说实话,如果没有 git 我现在都不能稳稳当当的做好一个项目。</span></p><p><br/></p><section style="border-bottom: 1px solid #ddd;margin: 0 auto 10px;"><p class="135brush" data-brushtype="text" style="padding: 0px 5px 6px; border-bottom-width: 2px; border-bottom-style: solid; border-bottom-color: rgb(239, 112, 96); display: inline-block; margin: 0px 0px -1px; font-weight: normal; line-height: 1.1; font-size: 18px;"><strong><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 16px;">Git 都改变了什么?</span></strong></p></section><p style="line-height: 1.75em;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">团队开发的协作方式</span></p><p style="line-height: 1.75em;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">1. 谁修改了代码引入了错误</span></p><p style="line-height: 1.75em;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">2. 让多个人同时开发,然后组合所有人的开发成果作为最终的产品。</span></p><p style="line-height: 1.75em; margin-top: 10px;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">更放心的尝试各种实现的方法和增加测试代码。如果你把你的所有记录都作为分支保留下来的话。</span></p><p><br/></p><section style="border-bottom: 1px solid #ddd;margin: 0 auto 10px;"><p class="135brush" data-brushtype="text" style="padding: 0px 5px 6px; border-bottom-width: 2px; border-bottom-style: solid; border-bottom-color: rgb(239, 112, 96); display: inline-block; margin: 0px 0px -1px; font-weight: normal; line-height: 1.1; font-size: 18px;"><strong><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 16px;">给大家使用 Git 的建议</span></strong></p></section><p style="line-height: 1.75em; margin-bottom: 10px;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">要按照工作的步骤提交代码,这样回顾的时候会更清晰。同时要及时提交代码,积累太久之后你基本无法按照模块提交你编写的代码。</span></p><p style="line-height: 1.75em; margin-bottom: 10px;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">解决冲突的时候一定要和产生冲突的人讨论,而不是自行决定如何解决冲突。解决冲突是一个看起来简单,但是实际会产生比较大的破坏性影响,同时对合并者要求比较高的技能。有些团队是让开发在提交 PR 的时候自行解决冲突,我认为这么做是不可取的。我们团队中,只有项目负责人才有权限合并代码。</span></p><p style="line-height: 1.75em; margin-bottom: 10px;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">一个清晰易懂,准确的 commit message。 如果你这么做了,那么即将有以下两个好处:</span></p><p style="line-height: 1.75em; margin-bottom: 10px;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">1. 更清晰的历史记录,如下图所示,每一次提交都有一个关键词描述对应的操作,关键词后面带上了具体的操作</span></p><p style="text-align: center;"></p><p style="line-height: 1.75em; margin-top: 10px;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">2. 更优美的代码,如果我们用得好,那么注释不应该存在。如下图,我使用 emacs(magit-blame) 来阅读 https://github.com/commitizen/cz-cli 项目的代码,可以快速的知道每一部分代码对应修改的原因。这样是不是比注释更加清晰?</span></p><p style="line-height: 1.75em; margin-top: 10px; text-align: center;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;"></span></p><p style="margin-top: 10px; line-height: 1.75em;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">同时还有两个好处:</span></p><p style="line-height: 1.75em;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">2.1 可以隐藏注释,在阅读之后我们开始修改之前可以隐藏掉 commit message</span></p><p style="line-height: 1.75em;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">2.2 不用维护重复性的东西,我们选择了 git 必然会有 commit message 而如果注释和 commit message 重复了,肯定要去掉一个不必要的内容。维护注释大家最常遇到的问题是在匆忙修改代码的时候忘了修改注释,这样不仅注释不能准确的解释代码,还可能会误导阅读代码的人。</span></p><p style="line-height: 1.75em;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;"><br/></span></p><p style="line-height: 1.75em; margin-top: 10px;"><br/></p><section style="border-bottom: 1px solid #ddd;margin: 0 auto 10px;"><p class="135brush" data-brushtype="text" style="padding: 0px 5px 6px; border-bottom-width: 2px; border-bottom-style: solid; border-bottom-color: rgb(239, 112, 96); display: inline-block; margin: 0px 0px -1px; font-weight: normal; line-height: 1.1; font-size: 18px;"><strong><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 16px;">有没有什么好的辅助工具帮助我们写出更好的 commit message?</span></strong></p></section><p style="line-height: 1.75em;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">1.http://www.ruanyifeng.com/blog/2016/01/commit_message_change_log.html这篇文章,清晰易懂。好的 commit message 还可以帮你输出好的 Changelog。</span></p><p style="line-height: 1.75em;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">2. https://github.com/commitizen/cz-conventional-changelog 这个工具已经非常完善,并且可以自己选择不同的模板。</span></p><p><br/></p><section style="border-bottom: 1px solid #ddd;margin: 0 auto 10px;"><p class="135brush" data-brushtype="text" style="padding: 0px 5px 6px; border-bottom-width: 2px; border-bottom-style: solid; border-bottom-color: rgb(239, 112, 96); display: inline-block; margin: 0px 0px -1px; font-weight: normal; line-height: 1.1; font-size: 18px;"><strong><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 16px;">我进行了什么尝试?</span></strong></p></section><p style="line-height: 1.75em;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">其实这个功能已经足够好用,但是作为一个 emacser, 习惯了使用 helm 来快速匹配选中的项。在输入 git cz 之后还需要手动去输入数字的编号来选择对应的 action 还是稍稍有点不舒服的。</span></p><p style="line-height: 1.75em;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">https://github.com/carlos-wong/conventional-changelog-fuzzy 我基于原有的插件修改了一个模板</span></p><p style="line-height: 1.75em;"><strong><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">安装方法:</span></strong></p><p style="text-align: center;"></p><p><strong><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">录屏:</span></strong></p><p style="text-align: center;"><strong><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;"></span></strong></p><p><strong><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;"><br/></span></strong></p><p><strong><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;"></span></strong></p><section style="border-bottom: 1px solid #ddd;margin: 0 auto 10px;"><p class="135brush" data-brushtype="text" style="padding: 0px 5px 6px; border-bottom-width: 2px; border-bottom-style: solid; border-bottom-color: rgb(239, 112, 96); display: inline-block; margin: 0px 0px -1px; font-weight: normal; line-height: 1.1; font-size: 18px;"><strong><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 16px;">总结</span></strong></p></section><p style="line-height: 1.75em; margin-bottom: 10px;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">工具不是提高技艺的必备条件,但是一个好的工具能帮助你更快地提高技艺。让你习惯好的设计哲学,好的使用习惯。例如:https://ruby-china.org/topics/2262。</span></p><p style="line-height: 1.75em; margin-bottom: 10px;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">所以在使用心得工具的时候,我都会看一下在emacs里面使用的习惯能否迁移过来。如果不行,那么我可能会选择在emacs里面寻找替代品。毕竟emacs是一个伪装成编辑器的操作系统。</span></p><p style="line-height: 1.75em; margin-bottom: 10px;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;"><br/></span></p><p style="line-height: 1.75em; margin-bottom: 10px;"><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;"><span style="overflow-wrap: break-word; font-weight: 700; color: rgb(51, 51, 51); font-family: -apple-system-font, Helvetica, PingFang SC, Hiragino Sans GB, Arial, Microsoft YaHei; background-color: rgb(255, 255, 255);"><span style="overflow-wrap: break-word; font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">文章来源:</span></span><span style="overflow-wrap: break-word; color: rgb(51, 51, 51); background-color: rgb(255, 255, 255); font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;">黄怀贤</span></span></p><p><strong><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;"></span></strong><br/></p><p><strong><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;"><br/></span></strong></p><p><strong><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;"><br/></span></strong></p><p><strong><span style="font-family: 微软雅黑, Microsoft YaHei; font-size: 14px;"><br/></span></strong></p><p><br/></p><p><br/></p><link rel="stylesheet" href="//bbs.lejurobot.com/source/plugin/wcn_editor/public/wcn_editor_fit.css?v134_kKx" id="wcn_editor_css"/>
页: [1]
查看完整版本: Git Cz , Fuzzy 让你飞起来